Repository navigation
Save warm library VMs, so javac's first compile skips its cold start - #48
Conversation
|
Warning Review limit reachedYou'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. View limit details
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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:
startLibrary({ warmSnapshot: true })cheerpjInit({ warmSnapshot: true }), which applies tocheerpjRunLibraryExisting options and CheerpJ names are unchanged.
How it works:
/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.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.Numbers (Pi 5):
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.pnpm build,pnpm typecheckandpnpm test(150 tests) pass.Noticed, not fixed: