Repository navigation
Keep snapshot images shallow so serializing and restoring them cannot overflow the stack - #59
Conversation
…h method's first call after a restore
…cannot overflow the stack
…store-depth # Conflicts: # src/snapshot.ts
|
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 10 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. |
…epth # Conflicts: # docs/browser.md # docs/node.md # src/jvm.ts # src/snapshot.ts # test/warm-jit.test.ts
There was a problem hiding this comment.
The PR introduces snapshot format 2 with a shallow encoding strategy: objects are inlined only to 64 levels of nesting, with deeper objects and repeated references stored in a flat table. The encoder uses a work-list and tracks leaf objects (strings, classes, threads, objects with only primitive fields) that are always shared directly. The decoder fills objects iteratively from the work list. A format check in jvm.ts rejects older images. New test snapshot-depth.test.ts validates a 200,000-node linked list restores correctly and that nesting stays under 400 levels. The warm-snapshot test now waits for the idle save event to avoid a race.
review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve
A warm snapshot restore no longer overflows the stack. Before, the restore sometimes failed and the VM silently booted cold, losing the warm start.
v8.deserialize,v8.serializeand the browser'sstructuredClonerecurse once per level of nesting. A snapshot image was one tree of records: each Java object's field list held the records of the objects it referred to, so a chain of N linked objects nested about 2N levels. A javac library VM's warm image nested 1668 levels. Whether that overflowed depended on how much stack the caller had left, so it happened intermittently, mostly for the second VM in a process. With a long linked list in the heap, master fails at the save too.tableon the image. Objects with nothing inside them (strings, classes, methods, fields, threads, objects with only primitive fields) stay shared directly, since they add one level at most.deserializeunder Node,structuredClonein the browser worker).format: 2. An image of another format is ignored, so the VM boots and saves a new one.test/warm-snapshot.test.tssometimes halted the VM before the idle save ran. It now waits for thewarm snapshot saved|busy|restoredevent.Nesting, before and after: warm image 1668 to 130 levels, boot snapshot 141 to 72.
Size and time, alternating runs:
The boot snapshot grows by 0.2 MB because the index pairs take more room than V8's own back-references. Restores are not slower.
tryEnc(from #58) now also undoes the index table and the shared-object set when a method's constants cannot be saved.Tests:
test/snapshot-depth.test.tsbuilds a 200,000-node doubly linked list in Java, saves a warm snapshot and restores it in a second VM in the same process. It checks that the restore happened, the list is intact, and the image nests less than 400 levels; it also checks the boot snapshot's nesting. On master it fails at the save.test/warm-snapshot.test.tspassed 10 runs in a row.pnpm typecheckandpnpm testpass.