Skip to content

feat: enable V8 code cache for host-platform binaries#8

Merged
BYK merged 1 commit into
mainfrom
feat/use-code-cache-same-platform
May 22, 2026
Merged

feat: enable V8 code cache for host-platform binaries#8
BYK merged 1 commit into
mainfrom
feat/use-code-cache-same-platform

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 22, 2026

Summary

When the build host is also a target platform, enable useCodeCache in the SEA config for that platform's binary. V8 code cache pre-compiles the JS into bytecode at build time, saving ~15% startup time.

Since code cache is CPU-architecture-specific, it can't be used for cross-compiled binaries. This PR handles all three scenarios:

Scenarios

Build Platforms Code Cache
Local (--single) Host only Yes — single blob with code cache
CI cross-compile Multiple including host Yes for host binary, no for others (two blobs)
CI cross-compile Multiple, host not in list No code cache

How it works

When cross-compiling multiple targets AND the host is one of them:

  1. Generate a base blob without code cache (for cross-compiled targets)
  2. Generate a second blob with code cache (for the host platform)
  3. Inject the appropriate blob per target

When building for a single platform that matches the host (common local-dev case), only one blob is generated with code cache enabled.

Benchmark (Sentry CLI, ~4MB CJS bundle, linux-x64)

Mode Avg Startup
No code cache ~870ms
With code cache ~740ms

~130ms / ~15% improvement with zero downsides for same-platform binaries.

When the build host is also a target platform, enable useCodeCache
in the SEA config for that platform's binary. Code cache pre-compiles
the JS into V8 bytecode at build time, saving ~15% startup time.

Since code cache is CPU-architecture-specific, it can't be used for
cross-compiled binaries. When building multiple targets that include
the host platform, two blobs are generated:
- Base blob (no code cache) for cross-compiled targets
- Code-cache blob for the host platform binary

When building for a single platform that matches the host (the common
local-dev case), only one blob is generated with code cache enabled.
@BYK BYK force-pushed the feat/use-code-cache-same-platform branch from a6c9dd8 to 1ebbad3 Compare May 22, 2026 18:47
@BYK BYK merged commit 51baac3 into main May 22, 2026
4 checks passed
@BYK BYK deleted the feat/use-code-cache-same-platform branch May 22, 2026 18:49
BYK added a commit to getsentry/cli that referenced this pull request May 22, 2026
Updates fossilize to v0.6.0 which automatically enables V8 code cache
for binaries matching the build host platform.

**Impact:** The linux-x64 binary (built on ubuntu-latest in CI) gets
~15% faster startup (~740ms vs ~870ms) from pre-compiled V8 bytecode.
Cross-compiled binaries (darwin, windows, linux-arm64) are unaffected —
code cache is CPU-architecture-specific.

See BYK/fossilize#8 for the fossilize change.
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