-
-
Notifications
You must be signed in to change notification settings - Fork 557
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
#1573 - added convenience API #1574
Conversation
d595fc0
to
e9ff41e
Compare
public void Setup() | ||
{ | ||
engine = new Engine(); | ||
parsedScript = new Esprima.JavaScriptParser().ParseScript(sourceCode); |
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.
you should use Engine.PrepareScript(sourceCode)
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.
aah... interesting.
Is this only for performance tests, or should we also use Engine.PrepareScript(xxx)
instead of new Esprima.JavaScriptParser().ParseScript(sourceCode);
in our production code?
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.
done - does not seem to make too much of a difference though:
Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
---|---|---|---|---|---|---|
ReusingEngine | 3,921.6 ns | 77.99 ns | 152.12 ns | 0.5417 | - | 3.34 KB |
NewEngineInstance | 10,940.6 ns | 216.49 ns | 361.71 ns | 2.7618 | 0.1373 | 16.93 KB |
ShadowRealm | 9,524.8 ns | 189.78 ns | 454.70 ns | 2.2888 | 0.1526 | 14.06 KB |
ReusingEngine_ParsedScript | 911.0 ns | 17.50 ns | 15.52 ns | 0.3204 | 0.0019 | 1.97 KB |
NewEngineInstance_ParsedScript | 5,345.5 ns | 77.00 ns | 94.57 ns | 2.5253 | 0.1297 | 15.51 KB |
ShadowRealm_ParsedScript | 4,677.5 ns | 71.50 ns | 63.38 ns | 2.0599 | 0.1373 | 12.64 KB |
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.
You should always prefer Engine.PrepareScript()
as it's the path that will get optimizations if they are possible. When script goes through the helper we can be assured that we can take our time to analyze more try to pre-calculate things. Otherwise Jint expects that this script might not be run multiple times (it doesn't know).
I recently pushed engine construction optimizations to main so you might want to rebase against it and see if things are better. NewEngineInstance
cases should be faster at least.
e9ff41e
to
2054d72
Compare
@gentledepp may I inquire the status of this PR, there's a lot of great work but still a draft and could probably land |
@lahma sure I will check tomorrow. Some tweaks === rebase && tests Green |
Exactly, sorry for the ambiguity. The API should be sound as it reflects non-shadow version. |
So... did a rebase. BenchmarkDotNet v0.13.7, Windows 11 (10.0.22621.2428/22H2/2022Update/SunValley2)
|
2054d72
to
f22e3d5
Compare
Are you happy with the code, should we merge? |
Yes, I am quite happy with it. But I am open for suggestions. The only thing that came to my mind was that it might be useful to have a common interface for the Engine and the ShadowRealm as far as the convenience API goes. (Sidenote: We actually tried to migrate to 3.x but experienced evaluation timeouts since then, so we had to switch back. Cannot wait until it is actually released :-D) |
f22e3d5
to
8b5600b
Compare
OK, I think we can bring this in, thanks for iterating.
Probably won't be fixed by release if there's still problems that we don't know of... |
Please do not merge - test fails!