snapshot: experimental warm-start heap-image (env-gated, draft)#23
Draft
littledivy wants to merge 1 commit into
Draft
snapshot: experimental warm-start heap-image (env-gated, draft)#23littledivy wants to merge 1 commit into
littledivy wants to merge 1 commit into
Conversation
Restore the pre-context isolate heap on warm runs by adopting whole mmap-able pages + a verbatim off-heap string-table blob instead of the per-object deserializer. Off by default; gated on DENO_HEAP_IMAGE_BAKE/ DENO_HEAP_IMAGE_RESTORE/DENO_HEAP_IMAGE_HASH_SEED. ~0.4ms end-to-end. Requires a pinned hash seed (disables HashDoS randomization) -- draft for discussion, not merge as-is.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Experimental warm-start heap-image for the snapshot deserializer: on a warm
run, restore the pre-context isolate heap by adopting whole mmap-able pages and a
verbatim off-heap string-table blob, instead of running the per-object snapshot
deserializer. Skips the object-graph walk and the string-table re-insertion.
All behavior is off by default and env-gated — zero effect on a normal build
unless
DENO_HEAP_IMAGE_BAKE/DENO_HEAP_IMAGE_RESTOREare set.This is posted as a draft for discussion, not for merge as-is (see Caveats).
How it works
DENO_HEAP_IMAGE_BAKE=<path>): after a normal startup deser, dumpevery adopted heap page (paged + large-object spaces, tagged by
AllocationSpace, global cage-offset order) plus the roots table, builtintable, startup/shared object caches, external-pointer slot table (by id+kind),
and the off-heap string table as a raw blob.
DENO_HEAP_IMAGE_RESTORE=<path>): allocate each page viaMemoryAllocator::AllocatePage/AllocateLargePageat the next sequential cageoffset (matches the bake since old/trusted space is empty), bulk-
memcpytheused area,
AddPage+Freethe tail. Re-resolve external pointers by id.Restore the string table by
memcpyof the bakedDatablob (compressedelement slots round-trip because pages land at identical cage offsets).
DENO_HEAP_IMAGE_HASH_SEED=<n>, read inHashSeed::InitializeRoots): makes the baked cached hashes valid on restore,so no rehash pass is needed -- this is most of the speed win.
Soundness relies on the post-deser boot heap being position-independent under
pointer compression (cage-relative 32-bit slots), so a whole-page image adopted
at identical cage offsets is valid without per-object relocation -- the same
property ART boot.art / HotSpot CDS archived heaps depend on.
Measured (arm64, release, deno console.log hello)
Internal phase (
DENO_STARTUP_PHASES):JsRuntime::new_innertotal: ~4.27ms -> ~3.34ms (~0.9ms)End-to-end wall-clock (warm, n=100, vs bun 1.3.5 for reference):
~0.4ms faster than baseline end-to-end; closes the deno-vs-bun gap from ~1.4ms
to ~1.0ms. Most of the ~0.9ms internal win is absorbed by fixed process/exec/
teardown cost shared with bun.
Caveats (why draft, not merge)
per-isolate HashDoS randomization. A shippable version needs a design here
(e.g. a per-install random-but-fixed seed baked into the image), not a global
constant.
normally.
DENO_HEAP_DUMP,DENO_SNAPSHOT_HISTO,DENO_RESTORE_BENCH,DENO_HEAP_IMAGE_VERBOSE).14.9-test-win-fix(what rusty_v8 v149.4.0 currently pins);retarget as appropriate.
Env knobs
DENO_HEAP_IMAGE_BAKE=<path>DENO_HEAP_IMAGE_RESTORE=<path>DENO_HEAP_IMAGE_HASH_SEED=<n>DENO_HEAP_IMAGE_VERBOSE=1