Skip to content

Generate compile caches for TypeScript bundles by default - #8339

Merged
floitsch merged 1 commit into
mainfrom
floitsch/builtin-bytecode-cache
Nov 17, 2026
Merged

floitsch merged 1 commit into
mainfrom
floitsch/builtin-bytecode-cache

Conversation

@floitsch

@floitsch floitsch commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Builtin TypeScript modules should load V8 compile caches generated with the executable's V8 build and flags. The bundle rule currently defaults cache generation off, so Cloudflare and static Pyodide modules compile their fixed source at runtime unless each caller opts in.

Make wd_ts_bundle() default to gen_compile_cache = True and remove Node's redundant explicit setting. Existing module loaders prefer embedded caches and retain source compilation as V8's rejection fallback. The lower-level wd_js_bundle() rule remains opt-in, preserving the separately distributed Pyodide runtime bundle: its artifact identity does not identify the consuming executable's V8 build and flags.

Require an embedded cache for every JavaScript module in the Cloudflare and static Pyodide bundles, compare one-byte and UTF-8 source strings, and verify V8 accepts each serialized module. Existing encoding-fixture and runtime cache-consumption checks remain covered.

The additional cache bytes grow the executable. Cache generation retains lazy compilation, and each isolate still deserializes its own bytecode.

@floitsch
floitsch marked this pull request as ready for review November 10, 2026 15:09
@floitsch
floitsch requested review from a team as code owners November 10, 2026 15:09

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Superseded by the review of 11eb9900.

This review, of b058f48e

✅ Approved — No issues found: the build changes are small and correct, and the new test checks that V8 accepts the cache for every JS module in both bundles.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

  • The header paths and bundle constants match the existing wd_js_bundle outputs and how the runtime already uses them.
  • gen_compile_cache only covers builtin and internal JS modules. The Python data modules are left out.
  • The \u2026 escape keeps the Vectorize source ASCII, so the legacy and UTF-8 loaders give the same source length.
  • The new test requires a non-empty cache for every source module, checks that the legacy and UTF-8 strings are equal, and asserts that V8 accepts the cache.

📝 Documentation: ✅ LGTM

No documentation issues. The new comment in the test describes the current behaviour.


Reviewed commit: b058f48e

@floitsch
floitsch force-pushed the floitsch/builtin-bytecode-cache branch from b058f48 to 11eb990 Compare November 10, 2026 15:17

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Superseded by the review of cdcf9a13.

This review, of 11eb9900

✅ Approved — No issues found. The escape keeps the Vectorize source ASCII so V8 accepts its cache, the build changes are correct, and the test checks every JavaScript module in both bundles.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

The \u2026 escape in vectorize-api.ts keeps the source ASCII, so the legacy and UTF-8 loaders read the same source and V8 accepts the cache. The build changes match the existing bundle rules. For every JavaScript module in both bundles, the test checks that a cache exists, that the legacy and UTF-8 source strings are equal, and that V8 accepts the cache.


📝 Documentation: ✅ LGTM

The new comments describe the current behaviour.


Reviewed commit: 11eb9900

@floitsch
floitsch requested a review from jasnell November 10, 2026 15:27

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Superseded by the review of 11eb9900.

This review, of cdcf9a13

✅ Approved — No issues found. The new commit only sets the encoding smoke benchmark and the WebSocket kill-switch test to size large, which matches nearby targets. The earlier compile-cache changes are unchanged and still correct.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

src/bench/streams/encoding/BUILD.bazel: encoding-cpp now uses size = "large", the same as its sibling encoding-ts. wd_bench passes size through to the @smoke test targets.

src/workerd/api/tests/BUILD.bazel: the kill-switch wd_test now uses size = "large", like the websocket-accept-limit-test target just above it. wd_test does read size, and the added comment explains why the test needs it.

The compile-cache changes have not changed since the last review and are still correct. The \u2026 escape keeps the Vectorize source ASCII, so V8 accepts its cache, and the test checks every JavaScript module in both bundles.


📝 Documentation: ✅ LGTM

The new comments describe how the code works now.


Reviewed commit: cdcf9a13

@floitsch
floitsch force-pushed the floitsch/builtin-bytecode-cache branch from cdcf9a1 to 11eb990 Compare November 16, 2026 12:27

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Superseded by the review of cd47d1ca.

This review, of 11eb9900

✅ Approved — No issues found: the compile caches are enabled with the existing bundle rules, the escape keeps the Vectorize source ASCII, and the new test checks that V8 accepts the cache for every JavaScript module in both bundles.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

  • Build changes: gen_compile_cache = True is forwarded correctly by wd_ts_bundle for both bundles, and the new test dependencies point at public targets.
  • Vectorize source: the \u2026 escape keeps the source ASCII, so the legacy and UTF-8 loaders build identical source strings.
  • Test: for every JavaScript module in both bundles, it requires a cache, compares the legacy and UTF-8 source strings, and asserts that V8 does not reject the cache.

📝 Documentation: ✅ LGTM

The new comments describe how the code works now.


Reviewed commit: 11eb9900

Builtin TypeScript bundles ship fixed source with the executable, but
omitting gen_compile_cache leaves them to compile that source at
runtime. Enable cache generation by default in wd_ts_bundle and remove
Node's redundant explicit setting.

Keep wd_js_bundle opt-in so separately distributed Pyodide runtime
bundles do not embed caches tied to an unrelated V8 build and flags.

Require caches for every JavaScript module in the Cloudflare and static
Pyodide bundles, check agreement between one-byte and UTF-8 sources,
and verify that V8 accepts each serialized module.
@floitsch
floitsch force-pushed the floitsch/builtin-bytecode-cache branch 2 times, most recently from b632fd3 to cd47d1c Compare November 16, 2026 13:00
@floitsch
floitsch requested a review from a team as a code owner November 16, 2026 13:00
@floitsch floitsch changed the title Embed compile caches for Cloudflare and static Pyodide modules Generate compile caches for TypeScript bundles by default Nov 16, 2026

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Approved — No findings: the default is moved into wd_ts_bundle correctly, wd_js_bundle stays opt-in, and the new test checks that every source module in the Cloudflare and static Pyodide bundles has a cache that V8 accepts.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

  • Default change: build/wd_ts_bundle.bzl now defaults gen_compile_cache to True and passes it on to wd_js_bundle, which still defaults to False. Node's build is unchanged now that src/node/BUILD.bazel drops its explicit setting, and the Cloudflare and static Pyodide bundles now get caches.
  • Test dependencies: //src/cloudflare and //src/pyodide:pyodide_static are public targets, and the CLOUDFLARE_BUNDLE / PYODIDE_BUNDLE constants are included the same way elsewhere in the code.
  • Test: the test covers only SRC modules, which are the only modules that get caches. For each one it requires a cache, checks that the one-byte and UTF-8 source strings are equal, and asserts that V8 does not reject the cache. It also requires at least one checked module per bundle.

📝 Documentation: ✅ LGTM

The new comments describe how the code works now.


Reviewed commit: cd47d1ca

@floitsch
floitsch merged commit fe4c75f into main Nov 17, 2026
37 of 38 checks passed
@floitsch
floitsch deleted the floitsch/builtin-bytecode-cache branch November 17, 2026 09:35
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.

3 participants