Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

ryzokuken
Copy link
Contributor

@ryzokuken ryzokuken commented Oct 23, 2018

Modify the NativeModule class to use compileFunction instead of manually
wrapping the string source code and then compiling it.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

/cc @devsnek @bcoe

Modify the NativeModule class to use compileFunction instead of manually
wrapping the string source code and then compiling it.
@bcoe
Copy link
Contributor

bcoe commented Oct 23, 2018

@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.

const script = new ContextifyScript(
source, this.filename, 0, 0,
cache, false, undefined
const fn = internalBinding('contextify').compileFunction(
Copy link
Member

@devsnek devsnek Oct 23, 2018

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@devsnek devsnek added the vm Issues and PRs related to the vm subsystem. label Oct 23, 2018
Copy link
Contributor

@bcoe bcoe left a 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)

cache,
false,
undefined,
[],
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.
@ryzokuken
Copy link
Contributor Author

@devsnek done! PTAL.

lib/internal/bootstrap/loaders.js Outdated Show resolved Hide resolved
lib/internal/bootstrap/loaders.js Show resolved Hide resolved
@ryzokuken
Copy link
Contributor Author

@joyeecheung @jdalton done! PTAL.

Copy link
Member

@joyeecheung joyeecheung left a 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!

lib/internal/bootstrap/loaders.js Show resolved Hide resolved
lib/internal/bootstrap/loaders.js Outdated Show resolved Hide resolved
lib/internal/bootstrap/loaders.js Outdated Show resolved Hide resolved
@ryzokuken
Copy link
Contributor Author

@joyeecheung done! PTAL.

@ryzokuken ryzokuken added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Oct 30, 2018
@ryzokuken
Copy link
Contributor Author

@@ -1099,12 +1099,23 @@ void ContextifyContext::CompileFunction(
env->cached_data_string(),
buf.ToLocalChecked()).IsNothing()) return;
}

// Report if cache was produced.
Copy link
Member

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.

Copy link
Member

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?

Copy link
Member

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?)

@Trott Trott removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Nov 2, 2018
@Trott
Copy link
Member

Trott commented Nov 6, 2018

@ryzokuken Is this still being worked on? (If yes, should we add an in progress label? If not, should we close it?)

@ryzokuken
Copy link
Contributor Author

@Trott it is! The discussion was moved into another sub-change which should be merged soon and unblock this one.

@joyeecheung
Copy link
Member

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..

@Trott Trott added the blocked PRs that are blocked by other issues or PRs. label Nov 6, 2018
@bcoe
Copy link
Contributor

bcoe commented Jan 19, 2019

@joyeecheung @ryzokuken I believe internal modules no longer have a wrapper prefix? is this work still needed?

Seems like the important issue is #21573

@ryzokuken
Copy link
Contributor Author

@bcoe IIRC, @joyeecheung took care of this. Working on merging the other one in.

@Trott
Copy link
Member

Trott commented Jun 23, 2020

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?

@ryzokuken
Copy link
Contributor Author

@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.

@gireeshpunathil
Copy link
Member

ping @ryzokuken to see if it is moving

@ryzokuken
Copy link
Contributor Author

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?

@bnb
Copy link
Contributor

bnb commented Jan 7, 2022

@ryzokuken any chance you're able to get to this?

@ryzokuken
Copy link
Contributor Author

@bnb sorry about that, I'll try to get back to it over the weekend.

@aduh95
Copy link
Contributor

aduh95 commented May 11, 2024

This needs a rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked PRs that are blocked by other issues or PRs. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.