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: stop copying code cache, part 2 #47958

Merged
merged 1 commit into from
May 15, 2023

Conversation

kvakil
Copy link
Contributor

@kvakil kvakil commented May 11, 2023

This removes more copies of the code cache data.

First: for the builtin snapshot, we were copying the code cache to create a std::vector<uint8_t>. This was slowing down static intialization. Change it to use a good old uint8_t* and size_t rather than a vector. For the case of embedder provided snapshots, we also add an owning_ptr so that we can properly cleanup owned values created from the snapshot.

Second: whenever the code cache was hit, we would remove the bytecode from the code cache, and then reserialize it from the compiled function. This was pretty slow. Change the code so that we can reuse the same code cache multiple times. If the code cache is rejected (say, because the user added V8 options), then we need to generate the bytecode, in which case we again use owning_ptr to ensure that the underlying code cache is freed.

Combined, these changes improve the misc/startup.js benchmarks significantly (p < 0.001):

  • process,benchmark/fixtures/require-builtins: 22.15%
  • process,test/fixtures/semicolon: 8.55%
  • worker,benchmark/fixtures/require-builtins: 26.52%
  • worker,test/fixtures/semicolon: 21.52%

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels May 11, 2023
This removes more copies of the code cache data.

First: for the builtin snapshot, we were copying the code cache to
create a `std::vector<uint8_t>`. This was slowing down static
intialization. Change it to use a good old `uint8_t*` and `size_t`
rather than a vector. For the case of embedder provided snapshots, we
also add an `owning_ptr` so that we can properly cleanup owned values
created from the snapshot.

Second: whenever the code cache was hit, we would remove the bytecode
from the code cache, and then reserialize it from the compiled function.
This was pretty slow. Change the code so that we can reuse the same code
cache multiple times. If the code cache is rejected (say, because the
user added V8 options), then we need to generate the bytecode, in which
case we again use `owning_ptr` to ensure that the underlying code cache
is freed.

Combined, these changes improve the misc/startup.js benchmarks
significantly (p < 0.001):

* process,benchmark/fixtures/require-builtins: 22.15%
* process,test/fixtures/semicolon: 8.55%
* worker,benchmark/fixtures/require-builtins: 26.52%
* worker,test/fixtures/semicolon: 21.52%
@kvakil kvakil added the request-ci Add this label to start a Jenkins CI on a PR. label May 11, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 11, 2023
@nodejs-github-bot
Copy link
Collaborator

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.

Nice find, I think the generation logic came from a time when we didn't generate the code cache at build time (we always generated the code cache so that workers can reuse the cache compiled by the main thread), but it's obsolete now that we pre-generate the code cache at build time..

@kvakil kvakil added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 12, 2023
@kvakil kvakil added commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. commit-queue Add this label to land a pull request using GitHub Actions. labels May 15, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 15, 2023
@nodejs-github-bot nodejs-github-bot merged commit 3ef17b6 into nodejs:main May 15, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in 3ef17b6

targos pushed a commit that referenced this pull request May 15, 2023
This removes more copies of the code cache data.

First: for the builtin snapshot, we were copying the code cache to
create a `std::vector<uint8_t>`. This was slowing down static
intialization. Change it to use a good old `uint8_t*` and `size_t`
rather than a vector. For the case of embedder provided snapshots, we
also add an `owning_ptr` so that we can properly cleanup owned values
created from the snapshot.

Second: whenever the code cache was hit, we would remove the bytecode
from the code cache, and then reserialize it from the compiled function.
This was pretty slow. Change the code so that we can reuse the same code
cache multiple times. If the code cache is rejected (say, because the
user added V8 options), then we need to generate the bytecode, in which
case we again use `owning_ptr` to ensure that the underlying code cache
is freed.

Combined, these changes improve the misc/startup.js benchmarks
significantly (p < 0.001):

* process,benchmark/fixtures/require-builtins: 22.15%
* process,test/fixtures/semicolon: 8.55%
* worker,benchmark/fixtures/require-builtins: 26.52%
* worker,test/fixtures/semicolon: 21.52%

PR-URL: #47958
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
@danielleadams danielleadams added the backport-requested-v18.x PRs awaiting manual backport to the v18.x-staging branch. label Jun 29, 2023
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. backport-requested-v18.x PRs awaiting manual backport to the v18.x-staging branch. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants