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

startup snapshot integration in packaging solutions #42566

Open
joyeecheung opened this issue Apr 1, 2022 · 5 comments
Open

startup snapshot integration in packaging solutions #42566

joyeecheung opened this issue Apr 1, 2022 · 5 comments
Labels
embedding Issues and PRs related to embedding Node.js in another project. snapshot Issues and PRs related to the startup snapshot

Comments

@joyeecheung
Copy link
Member

joyeecheung commented Apr 1, 2022

The recently landed build-time user-land snapshot is related to packaging solutions (e.g. pkg, nexe) in that if the user puts all the resources (modules, assets) in the snapshot, the compiled binary is a single-executable containing a bundle of user code, similar to what these packaging solutions produce, only that

  1. We do not provide APIs for the user to specify the run-time entry point in the snapshot entry point yet (it's a WIP), so for now you still have to start the deserialized app with another JS entry point script (i.e. you need to have two files to get it up and running)
  2. For now with these packaging solutions you'd usually still need to parse/execute some initialization code before the app is up and running, while with snapshots you can simply deserialize an initialized heap and may not have to execute the initialization code.

On the other hand, the user land snapshot we have right now is still a bit limited - a fair amount of builtins are not yet supported (pending more refactoring), and we still need to collect more user feedback to find states in builtins that might be out-of-sync with the system/native layer when being deserialized from the. snapshot. We also do not support user modules yet (the entry point must contain a bundle of all the modules that's needed by the app). In terms of user-experience, it might still be better to have some kind of tooling that allows users to load assets from the binary as if the assets are in the file system (i.e. virtual file system that packaging solutions provides).

I think that user snapshots in Node.js core is not a complete replacement of these packaging solutions (unless we decide to provide an "official" solution ourselves, but still packaging is different from just snapshotting), but rather it's something that packaging solutions can make use of (i.e. they can build a snapshot into the packaged binary too, while providing features like virtual file systems or compression of assets for a better user experience). So this is an issue to gather ideas and feedback, etc.

Refs: #42566

@joyeecheung joyeecheung added embedding Issues and PRs related to embedding Node.js in another project. snapshot Issues and PRs related to the startup snapshot labels Apr 1, 2022
@mhdawson
Copy link
Member

mhdawson commented Apr 7, 2022

Thanks for the perspective. If I understand correctly the suggestion is that startup snapshots are another tool that might be used in a Single Executable application to speed up startup, but not the way to build a Single Executable application. That makes sense to me.

@addaleax
Copy link
Member

@joyeecheung As you may know, we’re trying to use startup snapshots in our own packaging solution. This actually works very nicely for the most part, but we have run into the issue that we can’t distribute packaged SEAs with snapshots as easily because the ScriptCompiler::CachedDataVersionTag() values can mismatch just based on CPU features.

Would it make sense to add a snapshotting mode in which we don’t pass FunctionCodeHandling::kKeep and in return get a snapshot that can be used regardless of available CPU features?

@joyeecheung
Copy link
Member Author

joyeecheung commented Sep 27, 2023

Would it make sense to add a snapshotting mode in which we don’t pass FunctionCodeHandling::kKeep and in return get a snapshot that can be used regardless of available CPU features?

I am thinking about adding some kind of configuration API in v8.startupSnapshot, which allows users to configure this (probably makes sense to support a similar JSON config via command line, or a bunch of corresponding flags in the embedder API too). Another thing that also came up was the ability to disable warnings for unsupported modules after snapshot deserialization. Will probably have some sketch soon.

@addaleax
Copy link
Member

@joyeecheung That sounds awesome, yes! Please let me know if I can do something to help, this is probably the kind of thing I could spend some of my regular work time on 🙂

@joyeecheung
Copy link
Member Author

Actually on the particular issue about cpu features, after some discussions I believe it can just be ignored in the code cache version computation, so I uploaded https://chromium-review.googlesource.com/c/v8/v8/+/4905290 to remove it

joyeecheung added a commit to joyeecheung/v8 that referenced this issue Oct 29, 2023
…ag()

The code cache should be CPU-independent, we also do not actually check
this during the deserialization of code cache, so there is no need
to impose this in the embedder-facing CachedDataVersionTag() API.

Refs: nodejs/node#42566 (comment)

Change-Id: Ia1d677b949050add961af6fbf62c44342c061312
joyeecheung added a commit that referenced this issue Dec 15, 2023
- Add support for --build-snapshot-config which allows passing
  snapshot configurations via a JSON configuration file.
- Add support for node::SnapshotConfig in the embedder API

The initial configurable options are:

- "builder" (SnapshotConfig::builder_script_path): path to the
  builder script.
- "withoutCodeCache" (SnapshotFlags::kWithoutCodeCache): disable
  code cache generation.

PR-URL: #50453
Refs: #42566
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
joyeecheung pushed a commit that referenced this issue Dec 15, 2023
PR-URL: #50453
Refs: #42566
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
RafaelGSS pushed a commit that referenced this issue Jan 2, 2024
- Add support for --build-snapshot-config which allows passing
  snapshot configurations via a JSON configuration file.
- Add support for node::SnapshotConfig in the embedder API

The initial configurable options are:

- "builder" (SnapshotConfig::builder_script_path): path to the
  builder script.
- "withoutCodeCache" (SnapshotFlags::kWithoutCodeCache): disable
  code cache generation.

PR-URL: #50453
Refs: #42566
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
RafaelGSS pushed a commit that referenced this issue Jan 2, 2024
PR-URL: #50453
Refs: #42566
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
joyeecheung added a commit to joyeecheung/node that referenced this issue Jan 22, 2024
Original commit message:

    [api] Add v8::ScriptCompiler::CachedData::CompatibilityCheck()

    This patch adds a new API v8::ScriptCompiler::CachedData::CompatibilityCheck()
    in order to allow embedders to check if the code cache can be used in
    the current isolate without looking up for the source code. It also returns more detailed reasons about why the code cache cannot be used
    when it's bound to be rejected. This makes it possible to enforce
    portability checks in case code code becomes CPU-dependent in the
    future.

    Refs: nodejs#42566 (comment)

    Change-Id: Ia1d677b949050add961af6fbf62c44342c061312
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4905290
    Reviewed-by: Marja Hölttä <marja@chromium.org>
    Reviewed-by: Toon Verwaest <verwaest@chromium.org>
    Commit-Queue: Joyee Cheung <joyee@igalia.com>
    Cr-Commit-Position: refs/heads/main@{#90833}

Refs: v8/v8@efb1133
nodejs-github-bot pushed a commit that referenced this issue Feb 1, 2024
Original commit message:

    [api] Add v8::ScriptCompiler::CachedData::CompatibilityCheck()

    This patch adds a new API v8::ScriptCompiler::CachedData::CompatibilityCheck()
    in order to allow embedders to check if the code cache can be used in
    the current isolate without looking up for the source code. It also returns more detailed reasons about why the code cache cannot be used
    when it's bound to be rejected. This makes it possible to enforce
    portability checks in case code code becomes CPU-dependent in the
    future.

    Refs: #42566 (comment)

    Change-Id: Ia1d677b949050add961af6fbf62c44342c061312
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4905290
    Reviewed-by: Marja Hölttä <marja@chromium.org>
    Reviewed-by: Toon Verwaest <verwaest@chromium.org>
    Commit-Queue: Joyee Cheung <joyee@igalia.com>
    Cr-Commit-Position: refs/heads/main@{#90833}

Refs: v8/v8@efb1133
PR-URL: #51551
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
rdw-msft pushed a commit to rdw-msft/node that referenced this issue Feb 9, 2024
Original commit message:

    [api] Add v8::ScriptCompiler::CachedData::CompatibilityCheck()

    This patch adds a new API v8::ScriptCompiler::CachedData::CompatibilityCheck()
    in order to allow embedders to check if the code cache can be used in
    the current isolate without looking up for the source code. It also returns more detailed reasons about why the code cache cannot be used
    when it's bound to be rejected. This makes it possible to enforce
    portability checks in case code code becomes CPU-dependent in the
    future.

    Refs: nodejs#42566 (comment)

    Change-Id: Ia1d677b949050add961af6fbf62c44342c061312
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4905290
    Reviewed-by: Marja Hölttä <marja@chromium.org>
    Reviewed-by: Toon Verwaest <verwaest@chromium.org>
    Commit-Queue: Joyee Cheung <joyee@igalia.com>
    Cr-Commit-Position: refs/heads/main@{#90833}

Refs: v8/v8@efb1133
PR-URL: nodejs#51551
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
targos pushed a commit that referenced this issue Feb 15, 2024
Original commit message:

    [api] Add v8::ScriptCompiler::CachedData::CompatibilityCheck()

    This patch adds a new API v8::ScriptCompiler::CachedData::CompatibilityCheck()
    in order to allow embedders to check if the code cache can be used in
    the current isolate without looking up for the source code. It also returns more detailed reasons about why the code cache cannot be used
    when it's bound to be rejected. This makes it possible to enforce
    portability checks in case code code becomes CPU-dependent in the
    future.

    Refs: #42566 (comment)

    Change-Id: Ia1d677b949050add961af6fbf62c44342c061312
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4905290
    Reviewed-by: Marja Hölttä <marja@chromium.org>
    Reviewed-by: Toon Verwaest <verwaest@chromium.org>
    Commit-Queue: Joyee Cheung <joyee@igalia.com>
    Cr-Commit-Position: refs/heads/main@{#90833}

Refs: v8/v8@efb1133
PR-URL: #51551
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
marco-ippolito pushed a commit to marco-ippolito/node that referenced this issue Feb 19, 2024
Original commit message:

    [api] Add v8::ScriptCompiler::CachedData::CompatibilityCheck()

    This patch adds a new API v8::ScriptCompiler::CachedData::CompatibilityCheck()
    in order to allow embedders to check if the code cache can be used in
    the current isolate without looking up for the source code. It also returns more detailed reasons about why the code cache cannot be used
    when it's bound to be rejected. This makes it possible to enforce
    portability checks in case code code becomes CPU-dependent in the
    future.

    Refs: nodejs#42566 (comment)

    Change-Id: Ia1d677b949050add961af6fbf62c44342c061312
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4905290
    Reviewed-by: Marja Hölttä <marja@chromium.org>
    Reviewed-by: Toon Verwaest <verwaest@chromium.org>
    Commit-Queue: Joyee Cheung <joyee@igalia.com>
    Cr-Commit-Position: refs/heads/main@{#90833}

Refs: v8/v8@efb1133
PR-URL: nodejs#51551
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
richardlau pushed a commit that referenced this issue Mar 25, 2024
- Add support for --build-snapshot-config which allows passing
  snapshot configurations via a JSON configuration file.
- Add support for node::SnapshotConfig in the embedder API

The initial configurable options are:

- "builder" (SnapshotConfig::builder_script_path): path to the
  builder script.
- "withoutCodeCache" (SnapshotFlags::kWithoutCodeCache): disable
  code cache generation.

PR-URL: #50453
Refs: #42566
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
richardlau pushed a commit that referenced this issue Mar 25, 2024
PR-URL: #50453
Refs: #42566
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
embedding Issues and PRs related to embedding Node.js in another project. snapshot Issues and PRs related to the startup snapshot
Projects
None yet
Development

No branches or pull requests

3 participants