GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: compile code eagerly in snapshot builder by joyeecheung · Pull Request #51672 · nodejs/node

Conversation

@joyeecheung

@joyeecheung joyeecheung commented Feb 6, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

By default V8 only compiles the top-level function and skips code generation for inner functions - that would only be done when those inner functions are invoked. Since builtins are compiled as wrapped functions, most functions that look visually top-level are not actually included in the built-in code cache. For most of the builtins this is not too bad because usually only a subset of all builtin functions are needed by a particular
application and including all their code in the binary would incur an unnecessary size overhead. But there is also a subset of more commonly used builtins and it would be better to include the inner functions in the built-in code cache because they are more universally used by most applications.

This patch changes the compilation strategy to eager compilation
(including inner functions) for the following scripts:

  1. Primordials (internal/per_context/*), in all situations.
  2. Bootstrap scripts (internal/bootstrap/) and main scripts
    (internal/main/
    ), when being compiled for built-in code
    cache.
  3. Any scripts loaded during built-in snapshot generation.

We can't compile the code eagerly during snapshot generation
and include them into the V8 snapshot itself just now because
we need to start the inspector before context deserialization
for coverage collection to work. So leave that as a TODO.

With this patch the binary size increases by about 666KB
(~0.6% increase) in return the worker startup can be 18-19% faster.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@nodejs-github-bot

nodejs-github-bot commented Feb 6, 2024

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/startup
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Feb 6, 2024
@joyeecheung
joyeecheung force-pushed the eager-compile branch from fdbb5e4 to 034c68f Compare February 15, 2024 16:21
@joyeecheung

joyeecheung commented Feb 15, 2024

Copy link
Copy Markdown
Member Author

Just noticed that we can't compile the code eagerly during snapshot creation just yet because that requires refactoring of the V8ProfilerConnection classes. Added a TODO instead. The accompanying code cache is still compiled eagerly.

New numbers (only workers are more significantly impacted for now):

                                                                                     confidence improvement accuracy (*)   (**)  (***)
misc/startup-cli-version.js count=30 cli='deps/corepack/dist/corepack.js'                           -0.40 %       ±0.98% ±1.30% ±1.69%
misc/startup-cli-version.js count=30 cli='deps/npm/bin/npm-cli.js'                                  -0.15 %       ±0.74% ±0.99% ±1.29%
misc/startup-cli-version.js count=30 cli='deps/npm/bin/npx-cli.js'                                  -0.18 %       ±1.02% ±1.36% ±1.77%
misc/startup-cli-version.js count=30 cli='tools/node_modules/eslint/bin/eslint.js'                  -0.63 %       ±0.85% ±1.13% ±1.47%
misc/startup.js count=30 mode='process' script='benchmark/fixtures/require-builtins'                 1.11 %       ±2.52% ±3.37% ±4.42%
misc/startup.js count=30 mode='process' script='test/fixtures/semicolon'                             0.29 %       ±2.07% ±2.76% ±3.59%
misc/startup.js count=30 mode='worker' script='benchmark/fixtures/require-builtins'         ***     18.46 %       ±3.94% ±5.27% ±6.94%
misc/startup.js count=30 mode='worker' script='test/fixtures/semicolon'                     ***     19.29 %       ±4.84% ±6.47% ±8.46%
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung
joyeecheung force-pushed the eager-compile branch from 034c68f to e262e31 Compare February 15, 2024 17:41
@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Feb 15, 2024
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Feb 15, 2024
@joyeecheung
joyeecheung force-pushed the eager-compile branch 3 times, most recently from 4e42997 to c4020c3 Compare February 15, 2024 17:52
@nodejs nodejs deleted a comment from nodejs-github-bot Feb 15, 2024
@nodejs nodejs deleted a comment from nodejs-github-bot Feb 15, 2024
@nodejs-github-bot

nodejs-github-bot commented Feb 15, 2024

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/57109/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung
src: compile code eagerly in snapshot builder
fff0dbd
By default V8 only compiles the top-level function and
skips code generation for inner functions - that would
only be done when those inner functions are invoked.
Since builtins are compiled as wrapped functions, most
functions that look visually top-level are not actually
included in the built-in code cache. For most of the
builtins this is not too bad because usually only a subset of
all builtin functions are needed by a particular
application and including all their code in the binary
would incur an unnecessary size overhead. But there is also
a subset of more commonly used builtins and it would be
better to include the inner functions in the built-in
code cache because they are more universally used by
most applications.

This patch changes the compilation strategy to eager compilation
(including inner functions) for the following scripts:

1. Primordials (internal/per_context/*), in all situations.
2. Bootstrap scripts (internal/bootstrap/*) and main scripts
   (internal/main/*), when being compiled for built-in code
   cache.
3. Any scripts loaded during built-in snapshot generation.

We can't compile the code eagerly during snapshot generation
and include them into the V8 snapshot itself just now because
we need to start the inspector before context deserialization
for coverage collection to work. So leave that as a TODO.

With this patch the binary size increases by about 666KB
(~0.6% increase) in return the worker startup can be 18-19% faster.
@joyeecheung
joyeecheung force-pushed the eager-compile branch from c4020c3 to fff0dbd Compare February 15, 2024 17:53
@nodejs-github-bot

nodejs-github-bot commented Feb 15, 2024

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/57110/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anonrig
anonrig approved these changes Feb 15, 2024
View reviewed changes
@nodejs-github-bot

nodejs-github-bot commented Feb 16, 2024

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/57150/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Feb 20, 2024
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Feb 20, 2024
@nodejs-github-bot

nodejs-github-bot commented Feb 20, 2024

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/57183/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Feb 20, 2024

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/57208/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung added the commit-queue PRs queued for automated landing through the Commit Queue. label Feb 20, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Feb 20, 2024
@nodejs-github-bot
nodejs-github-bot merged commit 3e57b93 into nodejs:main Feb 20, 2024
@nodejs-github-bot

nodejs-github-bot commented Feb 20, 2024

Copy link
Copy Markdown
Collaborator

Landed in 3e57b93

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

marco-ippolito pushed a commit that referenced this pull request Feb 26, 2024
@joyeecheung @marco-ippolito
src: compile code eagerly in snapshot builder
0c41210
By default V8 only compiles the top-level function and
skips code generation for inner functions - that would
only be done when those inner functions are invoked.
Since builtins are compiled as wrapped functions, most
functions that look visually top-level are not actually
included in the built-in code cache. For most of the
builtins this is not too bad because usually only a subset of
all builtin functions are needed by a particular
application and including all their code in the binary
would incur an unnecessary size overhead. But there is also
a subset of more commonly used builtins and it would be
better to include the inner functions in the built-in
code cache because they are more universally used by
most applications.

This patch changes the compilation strategy to eager compilation
(including inner functions) for the following scripts:

1. Primordials (internal/per_context/*), in all situations.
2. Bootstrap scripts (internal/bootstrap/*) and main scripts
   (internal/main/*), when being compiled for built-in code
   cache.
3. Any scripts loaded during built-in snapshot generation.

We can't compile the code eagerly during snapshot generation
and include them into the V8 snapshot itself just now because
we need to start the inspector before context deserialization
for coverage collection to work. So leave that as a TODO.

With this patch the binary size increases by about 666KB
(~0.6% increase) in return the worker startup can be 18-19% faster.

PR-URL: #51672
Reviewed-By: Yagiz Nizipli <[email protected]>
@marco-ippolito marco-ippolito mentioned this pull request Mar 1, 2024
v21.7.0 proposal #51932
Merged
@joyeecheung joyeecheung mentioned this pull request Mar 8, 2024
src: use dedicated routine to compile function for builtin CJS loader #52016
Merged
richardlau pushed a commit that referenced this pull request Mar 25, 2024
@joyeecheung @richardlau
src: compile code eagerly in snapshot builder
90391ff
By default V8 only compiles the top-level function and
skips code generation for inner functions - that would
only be done when those inner functions are invoked.
Since builtins are compiled as wrapped functions, most
functions that look visually top-level are not actually
included in the built-in code cache. For most of the
builtins this is not too bad because usually only a subset of
all builtin functions are needed by a particular
application and including all their code in the binary
would incur an unnecessary size overhead. But there is also
a subset of more commonly used builtins and it would be
better to include the inner functions in the built-in
code cache because they are more universally used by
most applications.

This patch changes the compilation strategy to eager compilation
(including inner functions) for the following scripts:

1. Primordials (internal/per_context/*), in all situations.
2. Bootstrap scripts (internal/bootstrap/*) and main scripts
   (internal/main/*), when being compiled for built-in code
   cache.
3. Any scripts loaded during built-in snapshot generation.

We can't compile the code eagerly during snapshot generation
and include them into the V8 snapshot itself just now because
we need to start the inspector before context deserialization
for coverage collection to work. So leave that as a TODO.

With this patch the binary size increases by about 666KB
(~0.6% increase) in return the worker startup can be 18-19% faster.

PR-URL: #51672
Reviewed-By: Yagiz Nizipli <[email protected]>
@richardlau richardlau mentioned this pull request Mar 25, 2024
v20.12.0 proposal #52212
Merged
@joyeecheung joyeecheung mentioned this pull request Apr 15, 2024
module: implement NODE_COMPILE_CACHE for automatic on-disk code caching #52535
Closed
@joyeecheung joyeecheung mentioned this pull request Sep 20, 2024
module: implement flushCompileCache() #54971
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@anonrig anonrig anonrig approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@joyeecheung @nodejs-github-bot @anonrig
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.