bootstrap: optimize modules loaded in the built-in snapshot#45849
Closed
joyeecheung wants to merge 15 commits intonodejs:mainfrom
Closed
bootstrap: optimize modules loaded in the built-in snapshot#45849joyeecheung wants to merge 15 commits intonodejs:mainfrom
joyeecheung wants to merge 15 commits intonodejs:mainfrom
Conversation
Since the module has to be loaded during bootstrap anyway.
The helpers are actually shared by the two loaders, so move them under modules/ directly.
This patch adds a getLazy() method to facilitate initialize-once lazy loading in the internals.
So that the file can be snapshotted.
So that the file can be snapshotted
This moves the following utils into modules/esm/utils.js: - Code related to default conditions - The callbackMap (which is now created in the module instead of hanging off the module_wrap binding, since the C++ land does not need it). - Per-isolate module callbacks These are self-contained code that can be included into the built-in snapshot.
This patch makes the top-level access to runtime states in the CJS loader lazy, and move the side-effects into a initializeCJS() function that gets called during pre-execution. As a result the CJS loader can be included into the built-in snapshot.
Preload essential modules and lazy-load non-essential ones.
After this patch, all modules listed by running this snippet:
```
const list = process.moduleLoadList.join('\n');
require('fs').writeSync(1, list, 'utf-8');
```
(which is roughly the same list as the one in
test-bootstrap-module.js for the main thread)
are loaded from the snapshot so no additional compilation cost
is incurred.
Collaborator
|
Review requested:
|
Collaborator
Member
|
What’s the relationship between this PR and #45828? Is this just the first of the several commits you mentioned? |
Member
Author
|
@GeoffreyBooth This is a trimmed down version of #45828 that does not attempt to snapshot the ESM loader (except some really small bits) |
Member
|
Okay, well even still this seems like a significant improvement. The benchmarks you posted here are almost as good as in #45828, so it seems like you’ve achieved the bulk of the performance boost already in this PR alone. |
Member
Author
|
From the CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1264/ |
GeoffreyBooth
approved these changes
Dec 14, 2022
aduh95
reviewed
Dec 14, 2022
ljharb
reviewed
Dec 14, 2022
Collaborator
9 tasks
legendecas
reviewed
Dec 15, 2022
panva
pushed a commit
to joyeecheung/node
that referenced
this pull request
Jan 31, 2023
So that the file can be snapshotted. PR-URL: nodejs#45849 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
panva
pushed a commit
to joyeecheung/node
that referenced
this pull request
Jan 31, 2023
So that the file can be snapshotted PR-URL: nodejs#45849 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
panva
pushed a commit
to joyeecheung/node
that referenced
this pull request
Jan 31, 2023
This moves the following utils into modules/esm/utils.js: - Code related to default conditions - The callbackMap (which is now created in the module instead of hanging off the module_wrap binding, since the C++ land does not need it). - Per-isolate module callbacks These are self-contained code that can be included into the built-in snapshot. PR-URL: nodejs#45849 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
panva
pushed a commit
to joyeecheung/node
that referenced
this pull request
Jan 31, 2023
This patch makes the top-level access to runtime states in the CJS loader lazy, and move the side-effects into a initializeCJS() function that gets called during pre-execution. As a result the CJS loader can be included into the built-in snapshot. PR-URL: nodejs#45849 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
panva
pushed a commit
to joyeecheung/node
that referenced
this pull request
Jan 31, 2023
Preload essential modules and lazy-load non-essential ones.
After this patch, all modules listed by running this snippet:
```
const list = process.moduleLoadList.join('\n');
require('fs').writeSync(1, list, 'utf-8');
```
(which is roughly the same list as the one in
test-bootstrap-module.js for the main thread)
are loaded from the snapshot so no additional compilation cost
is incurred.
PR-URL: nodejs#45849
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Member
@juanarbol that's been done. This PR and #46225 should be unblocked now? |
targos
pushed a commit
to joyeecheung/node
that referenced
this pull request
Oct 28, 2023
PR-URL: nodejs#45849 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
targos
pushed a commit
to joyeecheung/node
that referenced
this pull request
Oct 28, 2023
Since the module has to be loaded during bootstrap anyway. PR-URL: nodejs#45849 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
targos
pushed a commit
to joyeecheung/node
that referenced
this pull request
Oct 28, 2023
The helpers are actually shared by the two loaders, so move them under modules/ directly. PR-URL: nodejs#45849 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
targos
pushed a commit
to joyeecheung/node
that referenced
this pull request
Oct 28, 2023
This patch adds a getLazy() method to facilitate initialize-once lazy loading in the internals. PR-URL: nodejs#45849 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
targos
pushed a commit
to joyeecheung/node
that referenced
this pull request
Oct 28, 2023
So that the file can be snapshotted. PR-URL: nodejs#45849 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
targos
pushed a commit
to joyeecheung/node
that referenced
this pull request
Oct 28, 2023
So that the file can be snapshotted PR-URL: nodejs#45849 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
targos
pushed a commit
to joyeecheung/node
that referenced
this pull request
Oct 28, 2023
This moves the following utils into modules/esm/utils.js: - Code related to default conditions - The callbackMap (which is now created in the module instead of hanging off the module_wrap binding, since the C++ land does not need it). - Per-isolate module callbacks These are self-contained code that can be included into the built-in snapshot. PR-URL: nodejs#45849 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
targos
pushed a commit
to joyeecheung/node
that referenced
this pull request
Oct 28, 2023
This patch makes the top-level access to runtime states in the CJS loader lazy, and move the side-effects into a initializeCJS() function that gets called during pre-execution. As a result the CJS loader can be included into the built-in snapshot. PR-URL: nodejs#45849 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
targos
pushed a commit
to joyeecheung/node
that referenced
this pull request
Oct 28, 2023
Preload essential modules and lazy-load non-essential ones.
After this patch, all modules listed by running this snippet:
```
const list = process.moduleLoadList.join('\n');
require('fs').writeSync(1, list, 'utf-8');
```
(which is roughly the same list as the one in
test-bootstrap-module.js for the main thread)
are loaded from the snapshot so no additional compilation cost
is incurred.
PR-URL: nodejs#45849
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
codebytere
added a commit
to electron/electron
that referenced
this pull request
Nov 6, 2023
codebytere
added a commit
to electron/electron
that referenced
this pull request
Nov 6, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To make the patch easier to review I have split it into smaller commits, though it's probably also okay to review the entire diff since most of the changes are superficial.
Locally I got:
bootstrap: support module_wrap binding in snapshot
bootstrap: include event_target into the built-in snapshot
Since the module has to be loaded during bootstrap anyway.
modules: move modules/cjs/helpers.js to modules/helpers.js
The helpers are actually shared by the two loaders, so move them
under modules/ directly.
lib: add getLazy() method to internal/util
This patch adds a getLazy() method to facilitate initialize-once
lazy loading in the internals.
lib: lazy-load deps in source_map_cache.js
So that the file can be snapshotted.
lib: lazy-load deps in modules/run_main.js
So that the file can be snapshotted
modules: move callbacks and conditions into modules/esm/utils.js
This moves the following utils into modules/esm/utils.js:
hanging off the module_wrap binding, since the C++ land
does not need it).
These are self-contained code that can be included into the
built-in snapshot.
bootstrap: make CJS loader snapshotable
This patch makes the top-level access to runtime states in the
CJS loader lazy, and move the side-effects into a
initializeCJS() function that gets called during pre-execution.
As a result the CJS loader can be included into the built-in
snapshot.
bootstrap: optimize modules loaded in the built-in snapshot
Preload essential modules and lazy-load non-essential ones.
After this patch, all modules listed by running this snippet:
(which is roughly the same list as the one in
test-bootstrap-module.js for the main thread)
are loaded from the snapshot so no additional compilation cost
is incurred.