-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
[v11.x backport] src: simplify NativeModule caching and remove redundant data #25964
Conversation
- Remove `NativeModule._source` - the compilation is now entirely done in C++ and `process.binding('natives')` is implemented directly in the binding loader so there is no need to store additional source code strings. - Instead of using an object as `NativeModule._cached` and insert into it after compilation of each native module, simply prebuild a JS map filled with all the native modules and infer the state of compilation through `mod.loading`/`mod.loaded`. - Rename `NativeModule.nonInternalExists` to `NativeModule.canBeRequiredByUsers` and precompute that property for all the native modules during bootstrap instead of branching in every require call during runtime. This also fixes the bug where `worker_threads` can be made available with `--expose-internals`. - Rename `NativeModule.requireForDeps` to `NativeModule.requireWithFallbackInDeps`. - Add a test to make sure we do not accidentally leak any module to the global namespace. PR-URL: nodejs#25352 Reviewed-By: Anna Henningsen <anna@addaleax.net>
I’ve added a fixup commit because it looks like this breaks a test? @joyeecheung is this is an okay way to address this? |
@addaleax Yes, looks it broke a test. Resume CI: https://ci.nodejs.org/job/node-test-pull-request/20634/ |
@nodejs/build-infra Could you take a look at the ARM failure? |
If it helps: Failure is:
Looks like it failed in (although the line number puts it on the Lines 447 to 454 in c5a7fed
|
@addaleax The fixup LGTM, I think it was caused by end-of-life of requiring v8 scripts but that’s not on v11 |
FTR: failure was because manual testing were performed concomitantly with the CI job. |
Resume CI again: https://ci.nodejs.org/job/node-test-commit/25690/ |
@refack It looks like that’s still ongoing … should we maybe just ignore the result for that machine? This is only a backport PR anyway. :/ |
Resume CI again: https://ci.nodejs.org/job/node-test-commit/25723/ |
Landed in b280d90, thanks for the backport! |
- Remove `NativeModule._source` - the compilation is now entirely done in C++ and `process.binding('natives')` is implemented directly in the binding loader so there is no need to store additional source code strings. - Instead of using an object as `NativeModule._cached` and insert into it after compilation of each native module, simply prebuild a JS map filled with all the native modules and infer the state of compilation through `mod.loading`/`mod.loaded`. - Rename `NativeModule.nonInternalExists` to `NativeModule.canBeRequiredByUsers` and precompute that property for all the native modules during bootstrap instead of branching in every require call during runtime. This also fixes the bug where `worker_threads` can be made available with `--expose-internals`. - Rename `NativeModule.requireForDeps` to `NativeModule.requireWithFallbackInDeps`. - Add a test to make sure we do not accidentally leak any module to the global namespace. Backport-PR-URL: #25964 PR-URL: #25352 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Backport: #25352
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes