-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Use JSON.parse instead of literal JS for callback formatting #1370
Conversation
Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.studio>
Tested the following conditions:
|
…uble String::replace())
Lines 9 to 55 in f57b533
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, just a few suggestions. Also, the formatting appears to be off, make sure to reformat the rpc.rs
file when you're done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now, great job!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this, such a clever PR!
Delete line 56 to fix the check btw. |
Looks like you need to rerun formatting on it :/ |
https://github.com/GoogleChromeLabs/json-parse-benchmark
What kind of change does this PR introduce? (check at least one)
Optimisation
Does this PR introduce a breaking change? (check one)
The PR fulfills these requirements:
Other information:
Believe it or not,
JSON.parse
is actually faster than directly evaluating literal JavaScript for JSON objects.It does actually make sense - when evaluating actual JavaScript the interpreter is looking for variables to interpolate, and is using a parsing pipeline made for interpreting actual code. Whereas with
JSON.parse
, it's just looking at raw JSON, which is of course much faster than interpreting actual JavaScript.This should introduce up to x2 speed improvements for formatting callback JS.
Unfortunately I don't know how to set up the dev environment for Tauri right now, it's very complex and I failed the last time I tried. Just want to get this PR up here so it will at least eventually be implemented. If I manage to get a dev environment set up or a maintainer can contribute (edits are on) then the following stuff needs doing for this PR to be complete:
{
or[
(the speed improvement only applies for JSON objects/arrays, not literals such as strings, booleans, numbers, etc.)