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: stop copying code cache by kvakil · Pull Request #47144 · nodejs/node

Conversation

@kvakil

@kvakil kvakil commented Mar 17, 2023

Copy link
Copy Markdown
Contributor

The code cache is quite large - around 1.3 MiB. Change the code to use non-owning buffers to avoid copying it. For starting up an otherwise empty main isolate, this saves around 1.3 MiB of unique set size memory (9.9 MiB -> 8.6 MiB) and 1.1ms elapsed time (22.9 ms -> 21.8 ms).

Copying the code cache is unnecessary since:

  1. for the builtin snapshot, the code cache data has static lifetime.
  2. for non-builtin snapshots, we create copies of the code cache data in SnapshotDeserializer::ReadVector. These copies are owned by the Environment (through IsolateData -> SnapshotData), so they won't be deallocated.
  3. a worker thread can copy a parent's isolate's code cache, but in that case we still know that the parent isolate will outlive the worker isolate.

(Admittedly point (2) feels a little fragile from a lifetime perspective, and I would be happy to restrict this optimization to the builtin snapshot.)

$ perf stat -r 100 -e ... ./node -e 0

 Performance counter stats for './node -e 0' (100 runs):

             21.78 msec task-clock
              2760      page-faults
         113161604      instructions
          18437648      branches
            423230      branch-misses
            853093      cache-references
             41474      cache-misses

         0.0225473 +- 0.0000504 seconds time elapsed  ( +-  0.22% )

$ perf stat -r 100 -e ... ./node-main -e 0

 Performance counter stats for './node-main -e 0' (100 runs):

             22.91 msec task-clock
              3102      page-faults
         114890673      instructions
          18751329      branches
            428909      branch-misses
            895721      cache-references
             45202      cache-misses

         0.0233760 +- 0.0000741 seconds time elapsed  ( +-  0.32% )

Sorry, something went wrong.

Uh oh!

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

bricss and lin72h reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@nodejs-github-bot

nodejs-github-bot commented Mar 17, 2023

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++. needs-ci PRs that need a full CI run. labels Mar 17, 2023
@kvakil kvakil 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 Mar 18, 2023
@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 Mar 18, 2023
@nodejs-github-bot

nodejs-github-bot commented Mar 18, 2023

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

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

@kvakil kvakil added the snapshot Issues and PRs related to the startup snapshot. label Mar 18, 2023
joyeecheung
joyeecheung approved these changes Mar 18, 2023
View reviewed changes

@joyeecheung joyeecheung left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % nits

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread src/node_builtins.cc Resolved

Uh oh!

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

Comment thread src/node_builtins.cc Resolved

Uh oh!

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

@joyeecheung

joyeecheung commented Mar 18, 2023

Copy link
Copy Markdown
Member

For 2) I think we can just document in node.h that the snapshot data must outlive the isolate/Environment. That's already the case internally.

All reactions

Sorry, something went wrong.

Uh oh!

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

anonrig
anonrig approved these changes Mar 18, 2023
View reviewed changes
@kvakil

kvakil commented Mar 19, 2023

Copy link
Copy Markdown
Contributor Author

For 2) I think we can just document in node.h that the snapshot data must outlive the isolate/Environment. That's already the case internally.

I added a line about this to the documentation of EmbedderSnapshotData. Other comments should also be addressed. PTAL :)

All reactions

Sorry, something went wrong.

Uh oh!

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

@kvakil kvakil 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 Mar 19, 2023
@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 Mar 19, 2023
@nodejs-github-bot

nodejs-github-bot commented Mar 19, 2023

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot mentioned this pull request Mar 20, 2023
CI Reliability 2023-03-20 nodejs/reliability#530
Open
17 tasks
legendecas
legendecas approved these changes Mar 20, 2023
View reviewed changes
addaleax
addaleax reviewed Mar 20, 2023
View reviewed changes
Comment thread src/node.h Outdated
Comment on lines 507 to 508

@addaleax addaleax Mar 20, 2023

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The snapshot *must* be kept alive during the execution of the environment /
// isolate that it is derived from.
// The snapshot *must* be kept alive during the execution of the Isolate
// that derives from it.

or

Suggested change
// The snapshot *must* be kept alive during the execution of the environment /
// isolate that it is derived from.
// The snapshot *must* be kept alive during the execution of the Isolate
// that was created using it.

(this header refers to Isolate/Environment as capitalized names to distinguish them from the regular English-language words; Environment instances do not outlive their Isolate instances; and the Isolate derives from the snapshot in this scenario, not the other way around, since this is about the case in which the snapshot is being consumed, not when it is being built)

Sorry, something went wrong.

Uh oh!

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

All reactions
@github-actions github-actions Bot mentioned this pull request Mar 21, 2023
CI Reliability 2023-03-21 nodejs/reliability#531
Open
19 tasks
@debadree25 debadree25 mentioned this pull request Mar 21, 2023
Flaky Test parallel/test-http-remove-connection-header-persists-connection #47200
Closed
@github-actions github-actions Bot mentioned this pull request Mar 22, 2023
CI Reliability 2023-03-22 nodejs/reliability#532
Open
19 tasks
kvakil added 5 commits April 10, 2023 00:08
@kvakil
src: stop copying code cache
52ce477
The code cache is quite large - around 1.3 MiB. Change the code to use
non-owning buffers to avoid copying it. For starting up an otherwise
empty main isolate, this saves around 1.3 MiB of unique set size memory
(9.9 MiB -> 8.6 MiB) and 1.1ms elapsed time (22.9 ms -> 21.8 ms).

Copying the code cache is unnecessary since:

1. for the builtin snapshot, the code cache data has static lifetime.
2. for non-builtin snapshots, we create copies of the code cache data in
   `SnapshotDeserializer::ReadVector`. These copies are owned by the
   `Environment` (through `IsolateData` -> `SnapshotData`), so they
   won't be deallocated.
3. a worker thread can copy a parent's isolate's code cache, but in that
   case we still know that the parent isolate will outlive the worker
   isolate.

(Admittedly point (2) feels a little fragile from a lifetime
perspective, and I would be happy to restrict this optimization to the
builtin snapshot.)

```console
$ perf stat -r 100 -e ... ./node -e 0

 Performance counter stats for './node -e 0' (100 runs):

             21.78 msec task-clock
              2760      page-faults
         113161604      instructions
          18437648      branches
            423230      branch-misses
            853093      cache-references
             41474      cache-misses

         0.0225473 +- 0.0000504 seconds time elapsed  ( +-  0.22% )

$ perf stat -r 100 -e ... ./node-main -e 0

 Performance counter stats for './node-main -e 0' (100 runs):

             22.91 msec task-clock
              3102      page-faults
         114890673      instructions
          18751329      branches
            428909      branch-misses
            895721      cache-references
             45202      cache-misses

         0.0233760 +- 0.0000741 seconds time elapsed  ( +-  0.32% )
```
@kvakil
fixup! src: stop copying code cache
7c6b5af
@kvakil
fixup! src: stop copying code cache
158062d
@kvakil
fixup! src: stop copying code cache
a286b91
@kvakil
fixup! src: stop copying code cache
eb99a86
@kvakil
kvakil force-pushed the doNotCopyCodeCache branch from f4833ff to eb99a86 Compare April 10, 2023 00:08
@kvakil kvakil 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 Apr 10, 2023
@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 Apr 10, 2023
@nodejs-github-bot

nodejs-github-bot commented Apr 10, 2023

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

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

@kvakil

kvakil commented Apr 10, 2023

Copy link
Copy Markdown
Contributor Author

I reworded the comment to @addaleax's suggestion. Test failures look like obvious flakes. PTAL.

All reactions

Sorry, something went wrong.

Uh oh!

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

This was referenced Apr 12, 2023
CI Reliability 2023-04-12 nodejs/reliability#541
Open
CI Reliability 2023-04-13 nodejs/reliability#542
Open
joyeecheung
joyeecheung approved these changes May 2, 2023
View reviewed changes
@nodejs-github-bot

nodejs-github-bot commented May 2, 2023

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

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

anonrig
anonrig approved these changes May 2, 2023
View reviewed changes
This was referenced May 3, 2023
CI Reliability 2023-05-03 nodejs/reliability#554
Open
CI Reliability 2023-05-04 nodejs/reliability#555
Open
CI Reliability 2023-05-05 nodejs/reliability#556
Open
@kvakil kvakil added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label May 5, 2023
@github-actions github-actions Bot mentioned this pull request May 6, 2023
CI Reliability 2023-05-06 nodejs/reliability#557
Open
22 tasks
@nodejs-github-bot

nodejs-github-bot commented May 6, 2023

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

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

@debadree25 debadree25 added commit-queue-squash PRs the Commit Queue should land as one squashed commit. commit-queue PRs queued for automated landing through the Commit Queue. labels May 6, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label May 7, 2023
@nodejs-github-bot
nodejs-github-bot merged commit 1e6e5a9 into nodejs:main May 7, 2023
@nodejs-github-bot

nodejs-github-bot commented May 7, 2023

Copy link
Copy Markdown
Collaborator

Landed in 1e6e5a9

All reactions

Sorry, something went wrong.

Uh oh!

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

targos pushed a commit that referenced this pull request May 12, 2023
@kvakil @targos
src: stop copying code cache
a11507e
The code cache is quite large - around 1.3 MiB. Change the code to use
non-owning buffers to avoid copying it. For starting up an otherwise
empty main isolate, this saves around 1.3 MiB of unique set size memory
(9.9 MiB -> 8.6 MiB) and 1.1ms elapsed time (22.9 ms -> 21.8 ms).

Copying the code cache is unnecessary since:

1. for the builtin snapshot, the code cache data has static lifetime.
2. for non-builtin snapshots, we create copies of the code cache data in
   `SnapshotDeserializer::ReadVector`. These copies are owned by the
   `Environment` (through `IsolateData` -> `SnapshotData`), so they
   won't be deallocated.
3. a worker thread can copy a parent's isolate's code cache, but in that
   case we still know that the parent isolate will outlive the worker
   isolate.

(Admittedly point (2) feels a little fragile from a lifetime
perspective, and I would be happy to restrict this optimization to the
builtin snapshot.)

```console
$ perf stat -r 100 -e ... ./node -e 0

 Performance counter stats for './node -e 0' (100 runs):

             21.78 msec task-clock
              2760      page-faults
         113161604      instructions
          18437648      branches
            423230      branch-misses
            853093      cache-references
             41474      cache-misses

         0.0225473 +- 0.0000504 seconds time elapsed  ( +-  0.22% )

$ perf stat -r 100 -e ... ./node-main -e 0

 Performance counter stats for './node-main -e 0' (100 runs):

             22.91 msec task-clock
              3102      page-faults
         114890673      instructions
          18751329      branches
            428909      branch-misses
            895721      cache-references
             45202      cache-misses

         0.0233760 +- 0.0000741 seconds time elapsed  ( +-  0.32% )
```

PR-URL: #47144
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
@targos targos mentioned this pull request May 15, 2023
v20.2.0 release proposal #48020
Merged
@kvakil kvakil mentioned this pull request May 26, 2023
Node.js Performance Team Meeting 2023-05-29 nodejs/performance#85
Closed
@danielleadams danielleadams added the backport-requested-v18.x label Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@addaleax addaleax addaleax left review comments
@anonrig anonrig anonrig approved these changes
@joyeecheung joyeecheung joyeecheung approved these changes
@legendecas legendecas legendecas approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash PRs the Commit Queue should land as one squashed commit. needs-ci PRs that need a full CI run. snapshot Issues and PRs related to the startup snapshot.

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.

8 participants

@kvakil @nodejs-github-bot @joyeecheung @addaleax @anonrig @legendecas @danielleadams @debadree25
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.