Open SimonDanisch opened 5 years ago
ping
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.
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.
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!