Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve speed [WIP] #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

SimonDanisch
Copy link
Collaborator

Surprisingly, broadcast seems to do really badly with empty lists & Vector{Any} results.
Removing the use of showable() made the biggest difference. Of course this can't stay like it, and we'll need to figure out a why to optimize this without giving up the functionality.
This branch, at least for my benchmark, is ~7x faster at constructing & rendering a dom!

@JeffreySarnoff
Copy link

ping

@tshort
Copy link
Contributor

tshort commented Sep 21, 2019

For the showable issue, it's slow because it uses hasmethod here. One option would be to set up a Dict filled in with some precomputed answers. Then, showable only needs to be called for types not checked, yet. try might be an easier option to try, too.

@tshort
Copy link
Contributor

tshort commented Oct 30, 2019

Here's a version that lessens the use of showable for commonly used types. With this, tests pass on @SimonDanisch's branch.

function renderdomchild(io, rctx::RenderContext, ctx, x)
    if x isa Number || x isa AbstractString
        printescaped(io, x, escapechild(ctx))
    elseif x isa HTML
        print(io, repr(MIME("text/html"), x))
    else
        showable(MIME("text/html"), x) ? print(io, repr(MIME("text/html"), x)) : printescaped(io, x, escapechild(ctx))
    end
end

Here's a test script:

using Markdown, Hyperscript, BenchmarkTools
@tags div h1
@btime repr($(div("hello", h1("qwerqwer"), 33, "asdf")))
@btime repr($(div("hello", h1("qwerqwer"), 33, "asdf", md"*asdf* asdf")))
@btime repr($(div("hello", h1("qwerqwer"), 33, "asdf", HTML("<div>hello</div>"))))

As a side note, static_hasmethod from Tricks.jl has interesting implications for easy traits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants