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

src: simplify NativeModule caching and remove redudant data #25352

Closed
wants to merge 2 commits into from

Conversation

joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented Jan 5, 2019

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

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Jan 5, 2019
@mscdex
Copy link
Contributor

mscdex commented Jan 5, 2019

Typo in commit message: s/redudant/redundant/

@joyeecheung
Copy link
Member Author

benchmark/fixtures/require-cachable.js Outdated Show resolved Hide resolved
- 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.
- Rename `NativeModule.requireForDeps` to
  `NativeModule.requireWithFallbackInDeps`.
- Add a test to make sure we do not accidentally leak any module
  to the global namespace.
@joyeecheung
Copy link
Member Author

@joyeecheung joyeecheung added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 12, 2019
@joyeecheung
Copy link
Member Author

Landed in 92e95f1

joyeecheung added a commit that referenced this pull request Jan 12, 2019
- 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: #25352
Reviewed-By: Anna Henningsen <[email protected]>
@addaleax
Copy link
Member

@joyeecheung Can you look into backporting this to v11.x-staging?

@BridgeAR
Copy link
Member

BridgeAR commented Jan 16, 2019

I pushed a backport directly onto v11.x-staging. There was just a minor conflict in lib/internal/bootstrap/loaders.js.

Seems like this requires a closer look.

@BridgeAR
Copy link
Member

This should be backported along #25481.

@BridgeAR BridgeAR mentioned this pull request Jan 16, 2019
2 tasks
@addaleax
Copy link
Member

ping @joyeecheung

antsmartian pushed a commit to antsmartian/node that referenced this pull request Feb 6, 2019
- 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 <[email protected]>
addaleax pushed a commit that referenced this pull request Feb 9, 2019
- 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 <[email protected]>
@targos targos mentioned this pull request Feb 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants