-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
lib: modify NativeModule to use compileFunction #23837
base: main
Are you sure you want to change the base?
Conversation
Modify the NativeModule class to use compileFunction instead of manually wrapping the string source code and then compiling it.
@ryzokuken awesome, thank you for doing this (I'm excited to see if it fixes some of the issues I was seeing around instrumenting internal modules for coverage). I will get some feedback to you tonight. |
lib/internal/bootstrap/loaders.js
Outdated
const script = new ContextifyScript( | ||
source, this.filename, 0, 0, | ||
cache, false, undefined | ||
const fn = internalBinding('contextify').compileFunction( |
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.
is there any reason to call internalBinding('contextify')
every time?
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.
Umm, it's only called once? Had it been called multiple times, I would have refactored it into a single destructure statement up top.
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.
its called every time we load an internal module, and we have a great many of those.
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.
@devsnek Oh wait, I get it now, sorry. Will change this.
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.
this seems to do the trick, and remove the necessity to take intro account wrapper length when calculating coverage (confirmed here).
It doesn't (as I'd hoped it might) solve the issue described here #22919 (comment)
lib/internal/bootstrap/loaders.js
Outdated
cache, | ||
false, | ||
undefined, | ||
[], |
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 think contextExtensions
can be undefined
too.
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.
@jdalton I used an empty array since that's the default value I used in vm.compileFunction
and wanted to make this as consistent as I could. I just rechecked the code to make sure, the two should be functionally similar, resulting in an empty std::vector<Local<Object>> context_extensions
.
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.
My point was more reducing throw away object creation.
Add functionality in vm.compileFunction/CompileFunction to report if cache data was provided yet rejected by v8.
@devsnek done! PTAL. |
@joyeecheung @jdalton done! PTAL. |
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.
Made a suggestion about commenting on the params. Let's try GitHub beta magic!
@joyeecheung done! PTAL. |
@@ -1099,12 +1099,23 @@ void ContextifyContext::CompileFunction( | |||
env->cached_data_string(), | |||
buf.ToLocalChecked()).IsNothing()) return; | |||
} | |||
|
|||
// Report if cache was produced. |
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 looked into the implementation a bit, and I wonder if we can just wrap ScriptCompiler::CreateCodeCacheForFunction
in another binding that takes a function as argument? That way we can just manipulate the return values in the JS land, and also enable the code cache generator to use the exact function compiled to generate the cache if we simply return fn
in NativeModule.prototype.compile
- also, we don't actually need that argument handling complexity in the compileFunction
C++ binding, vm.compileFunction
can handle produce_cached_data
in JS land and NativeModule.prototype.compile
doesn't even need it at all.
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.
Also I just noticed that the docs of vm.compileFunction
did not mention its return value. Is that intentional?
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.
(and the returned values are not tested either?)
@ryzokuken Is this still being worked on? (If yes, should we add an |
@Trott it is! The discussion was moved into another sub-change which should be merged soon and unblock this one. |
Pointer: #24069 Until that lands, or gets merged into this PR, it will fail the cache generation tests. Although even with that change, this still needs to fix the generator.. |
@joyeecheung @ryzokuken I believe internal modules no longer have a wrapper prefix? is this work still needed? Seems like the important issue is #21573 |
@bcoe IIRC, @joyeecheung took care of this. Working on merging the other one in. |
8ae28ff
to
2935f72
Compare
This looks like it may have been abandoned. Should we close this? We can re-open it if someone starts to work on it again? |
@Trott I had a talk with @joyeecheung about these, and looks like they still need some work. Please leave it open and I'd try to look deeper into it either later today or next week. |
ping @ryzokuken to see if it is moving |
I'm super sorry, but I've had no time as of late to finish this. If you don't mind leaving this open, I can try to look into it during vacations later this month or someone else would be interested to pick it up? |
@ryzokuken any chance you're able to get to this? |
@bnb sorry about that, I'll try to get back to it over the weekend. |
This needs a rebase. |
Modify the NativeModule class to use compileFunction instead of manually
wrapping the string source code and then compiling it.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes/cc @devsnek @bcoe