Skip to content

perf(core): avoid duplicating lazy ESM snapshot sources - #36262

Merged
nathanwhit merged 1 commit into
denoland:mainfrom
nathanwhit:agent/deduplicate-lazy-esm-snapshot-sources
Jul 23, 2026
Merged

nathanwhit merged 1 commit into
denoland:mainfrom
nathanwhit:agent/deduplicate-lazy-esm-snapshot-sources

Conversation

@nathanwhit

Copy link
Copy Markdown
Member

Summary

  • track lazy ESM specifiers alongside lazy JS specifiers while externalizing snapshot sources
  • serialize empty external-string slots for unconsumed lazy sources already present in the residual source table
  • assert that an unconsumed lazy ESM slot is empty and still loads successfully after restoring the snapshot

Why

The CLI snapshot sidecar retained all 615,312 bytes of its 104 unconsumed lazy ESM sources. The same sources are already embedded in the residual source table for first-use loading. Unconsumed lazy JS sources already used empty sidecar slots; this applies the same treatment to lazy ESM while preserving external-reference indices.

This does not add runtime decompression or a writable source buffer. The source remains available from the existing residual table.

Size impact

macOS arm64 release build with DENO_SNAPSHOT_MINIFY_SOURCES=1:

Before After Change
CLI snapshot 2,550,903 1,935,591 -615,312 bytes
__TEXT,__const 24,557,528 23,942,216 -615,312 bytes
linked binary 119,975,968 119,348,512 -627,456 bytes

The V8 blob is unchanged at 1,604,320 bytes; the sidecar drops from 946,575 to 331,263 bytes.

Validation

  • ./tools/format.js --check libs/core/runtime/bindings.rs libs/core/runtime/jsruntime.rs libs/core/runtime/tests/snapshot.rs
  • cargo test --locked -p deno_core

@nathanwhit
nathanwhit marked this pull request as ready for review July 22, 2026 23:44
@nathanwhit
nathanwhit merged commit c61f151 into denoland:main Jul 23, 2026
172 checks passed
bartlomieju pushed a commit that referenced this pull request Jul 23, 2026
## Summary

- track lazy ESM specifiers alongside lazy JS specifiers while
externalizing snapshot sources
- serialize empty external-string slots for unconsumed lazy sources
already present in the residual source table
- assert that an unconsumed lazy ESM slot is empty and still loads
successfully after restoring the snapshot

## Why

The CLI snapshot sidecar retained all 615,312 bytes of its 104
unconsumed lazy ESM sources. The same sources are already embedded in
the residual source table for first-use loading. Unconsumed lazy JS
sources already used empty sidecar slots; this applies the same
treatment to lazy ESM while preserving external-reference indices.

This does not add runtime decompression or a writable source buffer. The
source remains available from the existing residual table.

## Size impact

macOS arm64 release build with `DENO_SNAPSHOT_MINIFY_SOURCES=1`:

| | Before | After | Change |
|---|---:|---:|---:|
| CLI snapshot | 2,550,903 | 1,935,591 | -615,312 bytes |
| `__TEXT,__const` | 24,557,528 | 23,942,216 | -615,312 bytes |
| linked binary | 119,975,968 | 119,348,512 | -627,456 bytes |

The V8 blob is unchanged at 1,604,320 bytes; the sidecar drops from
946,575 to 331,263 bytes.

## Validation

- `./tools/format.js --check libs/core/runtime/bindings.rs
libs/core/runtime/jsruntime.rs libs/core/runtime/tests/snapshot.rs`
- `cargo test --locked -p deno_core`
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