Skip to content

perf(snapshot): minify snapshot sources#35183

Open
nathanwhit wants to merge 1 commit into
denoland:mainfrom
nathanwhit:snapshot-source-minify
Open

perf(snapshot): minify snapshot sources#35183
nathanwhit wants to merge 1 commit into
denoland:mainfrom
nathanwhit:snapshot-source-minify

Conversation

@nathanwhit

@nathanwhit nathanwhit commented Jun 12, 2026

Copy link
Copy Markdown
Member

Summary

This adds build-time minification for extension sources used by the startup snapshot.

When DENO_SNAPSHOT_MINIFY_SOURCES=1 is set, the snapshot build transpiles sources as before, then runs them through Rolldown's minifier with compression and name mangling disabled. This keeps the transform conservative: it removes whitespace/comments without changing binding names or applying semantic compression.

The minifier is applied to both sources consumed during snapshot creation and residual lazy extension sources emitted by cli/snapshot/build.rs. The minified output is asserted to be ASCII at snapshot build time.

Release CI now sets DENO_SNAPSHOT_MINIFY_SOURCES=1 for the release artifact builds and the benchmark release build, so release binaries exercise this path.

Why

Startup snapshot sources include a large amount of JavaScript/TypeScript text. Minifying those sources substantially reduces the serialized snapshot payload and residual embedded source size, even though it does not meaningfully reduce the deserialized V8 heap graph.

Measurements

Measured on a debug build from main@upstream with:

cargo build --bin deno -p deno
DENO_SNAPSHOT_MINIFY_SOURCES=1 cargo build --bin deno -p deno

Results:

CLI_SNAPSHOT.bin
7,149,430 -> 5,052,953
shrinks by 2,096,477 bytes = 29.32%

residual_sources
2,207,336 -> 1,387,948
shrinks by 819,388 bytes = 37.12%

combined file bytes
9,356,766 -> 6,440,901
shrinks by 2,915,865 bytes = 31.16%
2.78 MiB / 2.92 MB smaller

profile-deserialization bytes
2,710,184 -> 2,714,856
grows by 4,672 bytes = 0.17%

Validation

cargo build --bin deno -p deno
DENO_SNAPSHOT_MINIFY_SOURCES=1 cargo build --bin deno -p deno
deno check --lock=./tools/deno.lock.json .github/workflows/ci.ts

Also smoke-tested the minified debug binary with basic execution, node:path, URL, ReadableStream, and Deno.readTextFile.

@nathanwhit nathanwhit force-pushed the snapshot-source-minify branch from 8ec981d to fda6d6c Compare June 12, 2026 23:56
@nathanwhit nathanwhit marked this pull request as ready for review June 12, 2026 23:56
@nathanwhit nathanwhit force-pushed the snapshot-source-minify branch from fda6d6c to e98dbf2 Compare June 13, 2026 05:20
@nathanwhit nathanwhit force-pushed the snapshot-source-minify branch from e98dbf2 to 47ebe62 Compare June 13, 2026 05:30
Comment thread runtime/transpile.rs
console.error(JSON.stringify(result.errors, null, 2));
Deno.exit(1);
}
function escapeNonAscii(code) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this even reachable? I thought we have a check that ensures everything is ascii

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.

2 participants