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 — sea: snapshot support in single executable applications by joyeecheung · Pull Request #46824 · nodejs/node

Conversation

@joyeecheung

@joyeecheung joyeecheung commented Feb 24, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Refs: nodejs/single-executable#57

This patch adds snapshot support to single executable applications.
To build a snapshot from the main script when preparing the
blob that will be injected into the single executable application,
add "useSnapshot": true to the configuration passed to
--experimental-sea-config. For example:

{
    "main": "snapshot.js",
    "output": "sea-prep.blob",
    "useSnapshot": true
}

The main script used to build the snapshot must invoke
v8.startupSnapshot.setDeserializeMainFunction() to configure the
entry point. The generated startup snapshot would be part of the
preparation blob and get injected into the final executable.

When the single executable application is launched, instead of running
the main script from scratch, Node.js would instead deserialize the
snapshot to get to the state initialized during build-time directly.

$ /path/to/node --experimental-sea-config sea-config.json
$ cp /path/to/node sea
$ postject sea NODE_SEA_BLOB sea-prep.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2
$ ./sea

Sorry, something went wrong.

Uh oh!

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

debadree25, bricss, MomenNano, karlhorky, tony-go, benjamingr, justmoon, and Jaid reacted with heart emoji debadree25, piranna, styfle, benjamingr, MomenNano, and Jaid reacted with rocket emoji
All reactions
  • ❤️ 8 reactions
  • 🚀 6 reactions
@nodejs-github-bot

nodejs-github-bot commented Feb 24, 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++. 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 24, 2023
@RaisinTen

RaisinTen commented Feb 27, 2023

Copy link
Copy Markdown
Member

Thanks for doing this!

add some tooling to process the inputs

I personally really like this approach. I've opened a discussion in nodejs/single-executable#58, so that we can have a decision on this.

piranna and tony-go reacted with heart emoji
All reactions
  • ❤️ 2 reactions

Sorry, something went wrong.

Uh oh!

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

@joyeecheung joyeecheung mentioned this pull request Feb 27, 2023
src: share common code paths for SEA and embedder script #46825
Merged
@joyeecheung
joyeecheung force-pushed the sea-snapshot branch from d830718 to e94ac97 Compare March 2, 2023 20:07
@RaisinTen RaisinTen added the single-executable Issues and PRs related to single-executable applications. label May 12, 2023
@joyeecheung
joyeecheung force-pushed the sea-snapshot branch from e94ac97 to 8dec8b7 Compare June 10, 2023 22:45
@joyeecheung joyeecheung changed the title POC: snapshot support in single executable applications sea: snapshot support in single executable applications Jun 10, 2023
@joyeecheung

joyeecheung commented Jun 10, 2023

Copy link
Copy Markdown
Member Author

Rebased using the new SnapshotBuilder::Generate() overload added in #48242 and added a test. Will add more doc and tests next week but the implementation is there.

All reactions

Sorry, something went wrong.

Uh oh!

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

@piranna

piranna commented Jun 11, 2023

Copy link
Copy Markdown
Contributor

Rebased using the new SnapshotBuilder::Generate() overload added in #48242 and added a test. Will add more doc and tests next week but the implementation is there.

What's the difference between snapshot and code cache (bytenode)?

All reactions

Sorry, something went wrong.

Uh oh!

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

@joyeecheung
joyeecheung force-pushed the sea-snapshot branch from 8dec8b7 to eb703f7 Compare June 14, 2023 12:08
@nodejs-github-bot

This comment was marked as outdated.

Sign in to view
@joyeecheung

joyeecheung commented Jun 14, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member Author

What's the difference between snapshot and code cache (bytenode)?

If you have a bunch of top level code with a bunch of inner functions, usually when building the snapshot you run all the top level code and compile some of the inner functions, the snapshot contains the state of the heap after the top-level code is run and the bytecode of the inner functions that would be run again later. When deserializing the snapshot, you deserialize the state of an initialized heap (so there is no need to run the top-level code at all), and maybe later when the application invokes some of the inner functions, V8 deserialize the bytecode in the snapshot during the compilation of the function to speed things up. If there's just the code cache, what usually happens is that you have the bytecode of the top-level code and some inner functions. At runtime V8 deserializes the bytecode in the code cache to speed up compilation of the top-level code, but it still needs to run the top-level code to set up the heap.

All reactions

Sorry, something went wrong.

Uh oh!

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

@joyeecheung
joyeecheung force-pushed the sea-snapshot branch from eb703f7 to b91bfcd Compare June 14, 2023 13:16
@nodejs-github-bot

This comment was marked as outdated.

Sign in to view
@joyeecheung
joyeecheung force-pushed the sea-snapshot branch from b91bfcd to a71e4ac Compare June 14, 2023 14:03
@nodejs-github-bot

nodejs-github-bot commented Jun 14, 2023

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

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

@joyeecheung
joyeecheung marked this pull request as ready for review June 14, 2023 15:22
@joyeecheung

joyeecheung commented Jun 14, 2023

Copy link
Copy Markdown
Member Author

CI is almost green (with some flakes that look irrelevant). Can I have some reviews please? @nodejs/single-executable thanks!

All reactions

Sorry, something went wrong.

Uh oh!

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

@piranna

piranna commented Jun 14, 2023

Copy link
Copy Markdown
Contributor

If you have a bunch of top level code with a bunch of inner functions, usually when building the snapshot you run all the top level code and compile some of the inner functions, the snapshot contains the state of the heap after the top-level code is run and the bytecode of the inner functions that would be run again later. When deserializing the snapshot, you deserialize the state of an initialized heap (so there is no need to run the top-level code at all), and maybe later when the application invokes some of the inner functions, V8 deserialize the bytecode in the snapshot during the compilation of the function to speed things up. If there's just the code cache, what usually happens is that you have the bytecode of the top-level code and some inner functions. At runtime V8 deserializes the bytecode in the code cache to speed up compilation of the top-level code, but it still needs to run the top-level code to set up the heap.

Thank you @joyeecheung for your detailed explain :-) So, if I understood it correctly, a snapshoot is a combo of a module compiled and bytecode functions plus heap after executing the module top level code, while the code cache only have the bytecode of all the module code, isn't it?

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 Jun 15, 2023
CI Reliability 2023-06-15 nodejs/reliability#594
Open
22 tasks
@joyeecheung

joyeecheung commented Jun 15, 2023

Copy link
Copy Markdown
Member Author

So, if I understood it correctly, a snapshoot is a combo of a module compiled and bytecode functions plus heap after executing the module top level code, while the code cache only have the bytecode of all the module code, isn't it?

Roughly yes. V8 does not always emit bytecode for all the code it encounters (e.g. inner-inner functions are usually just parsed for syntax checks, but no bytecode is generated until they actually get executed). In some cases snapshots may contain more bytecode if during the snapshot building cases these functions are invoked.

piranna reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@piranna

piranna commented Jun 15, 2023

Copy link
Copy Markdown
Contributor

V8 does not always emit bytecode for all the code it encounters

Maybe bytenode is forcing its generation? Could it of our interest when generating the snapshots, so no Javascript code is included in it?

All reactions

Sorry, something went wrong.

Uh oh!

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

benjamingr
benjamingr approved these changes Jun 15, 2023
View reviewed changes

@benjamingr benjamingr 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

Sorry, something went wrong.

Uh oh!

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

All reactions
@benjamingr

benjamingr commented Jun 15, 2023

Copy link
Copy Markdown
Member

@RaisenTen can you please confirm you are comfortable with this based on nodejs/single-executable#58 and nodejs/single-executable#58 (reply in thread) landing

All reactions

Sorry, something went wrong.

Uh oh!

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

@joyeecheung

joyeecheung commented Jun 15, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member Author

Could it of our interest when generating the snapshots, so no Javascript code is included in it?

I would say that's not always a win, you could also have a lot of dead code in that application, or code that never gets run in many use cases, then eagerly generating code may result in a memory/size overhead that's not always worth it. As a configurable thing that might be useful though.

All reactions

Sorry, something went wrong.

Uh oh!

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

@RaisinTen

RaisinTen commented Jun 15, 2023

Copy link
Copy Markdown
Member

I can try to take a look day after tomorrow. (I'll be traveling pretty much the entire day tomorrow)

All reactions

Sorry, something went wrong.

Uh oh!

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

@piranna

piranna commented Jun 15, 2023

Copy link
Copy Markdown
Contributor

As a configurable thing that might be useful though.

Agree on that 👍🏻

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 Jul 20, 2023

Copy link
Copy Markdown
Collaborator

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

All reactions

Sorry, something went wrong.

Uh oh!

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

@joyeecheung joyeecheung added commit-queue PRs queued for automated landing through the Commit Queue. commit-queue-squash PRs the Commit Queue should land as one squashed commit. labels Jul 20, 2023
@nodejs-github-bot nodejs-github-bot added commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Jul 20, 2023
@nodejs-github-bot

nodejs-github-bot commented Jul 20, 2023

Copy link
Copy Markdown
Collaborator
Commit Queue failed
- Loading data for nodejs/node/pull/46824
✔  Done loading data for nodejs/node/pull/46824
----------------------------------- PR info ------------------------------------
Title      sea: snapshot support in single executable applications (#46824)
Author     Joyee Cheung  (@joyeecheung)
Branch     joyeecheung:sea-snapshot -> nodejs:main
Labels     c++, lib / src, needs-ci, commit-queue-squash, single-executable
Commits    4
 - src: support snapshot in single executable applications
 - fixup! src: support snapshot in single executable applications
 - fixup! fixup! src: support snapshot in single executable applications
 - fixup! fixup! fixup! src: support snapshot in single executable appli…
Committers 1
 - Joyee Cheung 
PR-URL: https://github.com/nodejs/node/pull/46824
Refs: https://github.com/nodejs/single-executable/discussions/57
Reviewed-By: Benjamin Gruenbaum 
Reviewed-By: Darshan Sen 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/46824
Refs: https://github.com/nodejs/single-executable/discussions/57
Reviewed-By: Benjamin Gruenbaum 
Reviewed-By: Darshan Sen 
--------------------------------------------------------------------------------
   ℹ  This PR was created on Fri, 24 Feb 2023 18:28:13 GMT
   ✔  Approvals: 2
   ✔  - Benjamin Gruenbaum (@benjamingr) (TSC): https://github.com/nodejs/node/pull/46824#pullrequestreview-1482036842
   ✔  - Darshan Sen (@RaisinTen) (TSC): https://github.com/nodejs/node/pull/46824#pullrequestreview-1538950503
   ✘  Last GitHub CI failed
   ℹ  Last Full PR CI on 2023-07-20T18:44:40Z: https://ci.nodejs.org/job/node-test-pull-request/52874/
- Querying data for job/node-test-pull-request/52874/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/5615590467
All reactions

Sorry, something went wrong.

Uh oh!

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

@joyeecheung joyeecheung added commit-queue PRs queued for automated landing through the Commit Queue. and removed commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. labels Jul 20, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Jul 20, 2023
@nodejs-github-bot
nodejs-github-bot merged commit ac34e75 into nodejs:main Jul 20, 2023
@nodejs-github-bot

nodejs-github-bot commented Jul 20, 2023

Copy link
Copy Markdown
Collaborator

Landed in ac34e75

All reactions

Sorry, something went wrong.

Uh oh!

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

piranna
piranna reviewed Jul 20, 2023
View reviewed changes
Comment thread doc/api/single-executable-applications.md
### Startup snapshot support
The `useSnapshot` field can be used to enable startup snapshot support. In this
case the `main` script would not be when the final executable is launched.

@piranna piranna Jul 20, 2023

Copy link
Copy Markdown
Contributor

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.

It's missing a run: "would not be run"

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 Jul 21, 2023
CI Reliability 2023-07-21 nodejs/reliability#619
Open
16 tasks
This was referenced Jul 22, 2023
CI Reliability 2023-07-22 nodejs/reliability#620
Open
CI Reliability 2023-07-23 nodejs/reliability#621
Open
CI Reliability 2023-07-24 nodejs/reliability#622
Open
CI Reliability 2023-07-25 nodejs/reliability#623
Open
@karlhorky karlhorky mentioned this pull request Jul 25, 2023
Use built-in single executable application support in Node.js once it is released jonaschlegel/lgo-agisoft-converter#2
Open
This was referenced Jul 26, 2023
CI Reliability 2023-07-26 nodejs/reliability#624
Open
CI Reliability 2023-07-27 nodejs/reliability#625
Open
CI Reliability 2023-07-28 nodejs/reliability#626
Open
CI Reliability 2023-07-29 nodejs/reliability#627
Open
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Aug 14, 2023
@joyeecheung @Ceres6
src: support snapshot in single executable applications
14a1cfe
This patch adds snapshot support to single executable applications.
To build a snapshot from the main script when preparing the
blob that will be injected into the single executable application,
add `"useSnapshot": true` to the configuration passed to
`--experimental-sea-config`. For example:

```
{
    "main": "snapshot.js",
    "output": "sea-prep.blob",
    "useSnapshot": true
}
```

The main script used to build the snapshot must invoke
`v8.startupSnapshot.setDeserializeMainFunction()` to configure the
entry point. The generated startup snapshot would be part of the
preparation blob and get injected into the final executable.

When the single executable application is launched, instead of running
the `main` script from scratch, Node.js would instead deserialize the
snapshot to get to the state initialized during build-time directly.

PR-URL: nodejs#46824
Refs: nodejs/single-executable#57
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Ceres6 pushed a commit to Ceres6/node that referenced this pull request Aug 14, 2023
@joyeecheung @Ceres6
src: support snapshot in single executable applications
9b754bd
This patch adds snapshot support to single executable applications.
To build a snapshot from the main script when preparing the
blob that will be injected into the single executable application,
add `"useSnapshot": true` to the configuration passed to
`--experimental-sea-config`. For example:

```
{
    "main": "snapshot.js",
    "output": "sea-prep.blob",
    "useSnapshot": true
}
```

The main script used to build the snapshot must invoke
`v8.startupSnapshot.setDeserializeMainFunction()` to configure the
entry point. The generated startup snapshot would be part of the
preparation blob and get injected into the final executable.

When the single executable application is launched, instead of running
the `main` script from scratch, Node.js would instead deserialize the
snapshot to get to the state initialized during build-time directly.

PR-URL: nodejs#46824
Refs: nodejs/single-executable#57
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
UlisesGascon pushed a commit to UlisesGascon/node that referenced this pull request Aug 14, 2023
@joyeecheung @UlisesGascon
src: support snapshot in single executable applications
268c119
This patch adds snapshot support to single executable applications.
To build a snapshot from the main script when preparing the
blob that will be injected into the single executable application,
add `"useSnapshot": true` to the configuration passed to
`--experimental-sea-config`. For example:

```
{
    "main": "snapshot.js",
    "output": "sea-prep.blob",
    "useSnapshot": true
}
```

The main script used to build the snapshot must invoke
`v8.startupSnapshot.setDeserializeMainFunction()` to configure the
entry point. The generated startup snapshot would be part of the
preparation blob and get injected into the final executable.

When the single executable application is launched, instead of running
the `main` script from scratch, Node.js would instead deserialize the
snapshot to get to the state initialized during build-time directly.

PR-URL: nodejs#46824
Refs: nodejs/single-executable#57
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
RafaelGSS pushed a commit that referenced this pull request Aug 15, 2023
@joyeecheung @RafaelGSS
src: support snapshot in single executable applications
5dec186
This patch adds snapshot support to single executable applications.
To build a snapshot from the main script when preparing the
blob that will be injected into the single executable application,
add `"useSnapshot": true` to the configuration passed to
`--experimental-sea-config`. For example:

```
{
    "main": "snapshot.js",
    "output": "sea-prep.blob",
    "useSnapshot": true
}
```

The main script used to build the snapshot must invoke
`v8.startupSnapshot.setDeserializeMainFunction()` to configure the
entry point. The generated startup snapshot would be part of the
preparation blob and get injected into the final executable.

When the single executable application is launched, instead of running
the `main` script from scratch, Node.js would instead deserialize the
snapshot to get to the state initialized during build-time directly.

PR-URL: #46824
Refs: nodejs/single-executable#57
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
@UlisesGascon UlisesGascon mentioned this pull request Aug 15, 2023
v20.6.0 proposal #49185
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@benjamingr benjamingr benjamingr approved these changes
@RaisinTen RaisinTen RaisinTen approved these changes
+2 more reviewers
@piranna piranna piranna left review comments
@aymen94 aymen94 aymen94 approved these changes
Reviewers whose approvals may not affect merge requirements

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++. commit-queue-squash PRs the Commit Queue should land as one squashed commit. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. single-executable Issues and PRs related to single-executable applications.

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.

6 participants

@joyeecheung @nodejs-github-bot @RaisinTen @piranna @benjamingr @aymen94
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.