Closed Plasmatium closed 5 years ago
Hello, thanks for all the testing.
Using a string as a key should of course be possible, there obviously isn't support right now but that would be probably just one line, I'll work on that.
Regarding the timing: you have to be a bit careful with timing macros, I suppose. Macros are evaluated compile-time, whereas you're interested in runtime performance.
Your string parsing function could be simpler: there is the non-exported JSObjectLiteral.js(expr::Expr)
so that you could write:
jsonParse(s::AbstractString) = JSObjectLiteral.js(Meta.parse(s))
But realize that the whole idea is that you use JSObjectLiteral to convert Julia code, parsed by the julia compiler, to javascript-like objects. This way you're effectively making js()
a run-time javascript-object parser, using the Julia parser.
This is an excellent work!!!
Maybe bugs or missing features
Consider this:
I got an error here in Julia
feature request
Is there any way to make functions like
JSON.parse
andJSON.stringify
that similar in javascript? I had tried this, but got some performance issue:But didn't find a way to dump dict generated by
@js
to json stringperformance issue
I had a large json string (3748 length).
first on chrome v8:
Julia with
@js
really fast, but I don't know if there could be some cache here, or run the whole relevant parsing code each sample.
here is JSON (JSON2 is slightly slower)
also faster than chrome v8 and slightly slower than JSObjectLiteral(
@js
) butJSON.json
in julia cost 68.794us, 4x time cost asJSON.stringify
in chrome v8(cost 16.3us)But if I use that wrapper function shown before, it hurt performance a lot.
I tried to split into two process: process for parsing the code and process for evaluation
I'm new to Julia, maybe something awesome I missed for parsing and eval code fast.
At last, this is an excellent work!!! I like this repo