Skip to content

Save warm library VMs, so javac's first compile skips its cold start - #48

Merged
Project516 merged 5 commits into
masterfrom
p516/warm-snapshot
Nov 5, 2026
Merged

Project516 merged 5 commits into
masterfrom
p516/warm-snapshot

Conversation

@Project516

Copy link
Copy Markdown
Owner

A library-mode VM can now be saved again once its calls have warmed it up, and later starts restore that warm VM instead of the boot snapshot. The main case is javac: its first compile in a fresh VM takes about 6 s on a Raspberry Pi 5, later ones about 1 s. Opt-in with one option:

  • Node: startLibrary({ warmSnapshot: true })
  • Browser: cheerpjInit({ warmSnapshot: true }), which applies to cheerpjRunLibrary

Existing options and CheerpJ names are unchanged.

How it works:

  • After boot, the VFS records what the VM touches outside /jdk: each file read (a SHA-256 of its bytes), each path looked up that did not exist, and each directory listing. The JDK image is already part of the boot snapshot key.
  • After a library call returns, once at least 200 classes have loaded since boot (one javac compile loads over a thousand) and no library handles are live, the VM is saved with that record. Files the VM itself changed while warming up, such as javac's output, are recorded as they are at save time, so they do not make the next start miss.
  • A later start with the same boot key, class path, working directory and command checks the record against the VFS (same bytes, still missing, same listings) and restores the warm image. Any difference drops the image and starts from the boot snapshot.
  • Read-only open files (javac's image reader, ZipFile's jars) are saved by path and position and reopened on restore. A written or dirty file, an active continuation, live handles or a record over 128 KB skip the save, logged as busy.
  • Method caches (indy call sites) are saved too, so a restored VM does not relink and re-spin lambda classes.
  • Warm images are cached apart from boot snapshots: 2 under Node (snapshot directory) and 2 in IndexedDB. One is about 18 MB.

Numbers (Pi 5):

from boot snapshot from warm snapshot
Node: restore 263 ms 604 ms
Node: first javac compile 5.67 s 1.20 s
Browser (headless Chromium): library start 1.6 s 0.9 s
Browser: first javac compile 5.3 s 2.7 s

Tests:

  • test/warm-snapshot.test.ts (Node): compiles with javac in library mode, restarts and checks the warm image was restored, that the output the warm-up wrote does not make it miss, that changing the source it read misses, and that creating a path it found missing misses. Compiled bytes match HotSpot's.
  • The browser numbers come from a page that runs the self-test's compile twice, loaded twice in one Chromium profile.
  • pnpm build, pnpm typecheck and pnpm test (150 tests) pass.

Noticed, not fixed:

  • In the browser the warm compile is 2.7 s, not about 1.3 s as under Node. A likely cause is that each page fetches the javac class bytes the restore parses again, while Node reads them from disk. Worth measuring before the next release.

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 42295514-0041-49d8-b6fc-76c256ea28d2
Commits

Reviewing files that changed from the base of the PR and between 509713f and 7d76425.

Files selected for processing: 17

  • docs/browser.md
  • docs/node.md
  • src/browser/api.ts
  • src/browser/idb.ts
  • src/browser/protocol.ts
  • src/browser/worker.ts
  • src/fs.ts
  • src/jvm.ts
  • src/library.ts
  • src/natives/continuation.ts
  • src/natives/crypto.ts
  • src/natives/io.ts
  • src/node.ts
  • src/snapshot.ts
  • test/warm-snapshot.test.ts
  • test/warm-snapshot/WarmJavac.java
  • types/node.d.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR adds warm snapshot support for library-mode VMs: after a library call loads ≥200 classes and no handles/continuations/files are busy, the VM is saved with a trace of file reads, missing paths, and directory listings. Later starts with the same boot key, classpath, cwd, and command validate the trace against the VFS and restore the warm image (≈18 MB, 2 kept per platform). The change spans VFS tracing, JVM save/restore, continuation tracking, IndexedDB/node filesystem storage, and protocol options. Tests pass and cover restore, validation of reads/missing/listings, and that warm-up output files don't cause misses.


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict request_changes

Comment thread src/jvm.ts Resolved
Comment thread src/fs.ts Resolved
Comment thread src/jvm.ts Resolved

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All points from the last review are settled in the threads.


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR adds warm snapshot support for library-mode VMs: after a library call returns, once ≥200 classes have loaded since boot and no handles/continuations are live, the VM is saved with a trace of file reads (SHA-256), missing paths, and directory listings. Later starts with the same boot key, classpath, cwd, and command validate the trace against the VFS and restore the warm image, skipping javac's cold start. Warm images are cached separately from boot snapshots (2 in IndexedDB / 2 on disk, ~18 MB each).


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict request_changes

Comment thread src/jvm.ts Resolved

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All points from the last review are settled in the threads.


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve

@Project516
Project516 enabled auto-merge (squash) November 5, 2026 16:22
@Project516
Project516 merged commit cead124 into master Nov 5, 2026
16 checks passed
@Project516
Project516 deleted the p516/warm-snapshot branch November 5, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

⌂ Proxy