Skip to content

CodeCache: function-executable cache entry + depth-bounded eager generation - #344

Draft
Jarred-Sumner wants to merge 3 commits into
mainfrom
claude/builtin-bytecode-depth
Draft

Jarred-Sumner wants to merge 3 commits into
mainfrom
claude/builtin-bytecode-depth

Conversation

@Jarred-Sumner

Copy link
Copy Markdown
Collaborator

Two additions needed to cache builtin-module bytecode in Bun (builtins compile as function executables, and only their top-level block is worth caching):

  • A CachedFunctionExecutableTag top-level cache entry (encodeFunctionExecutable / decodeFunctionExecutable / sourceCodeKeyForSerializedFunctionExecutable, recursivelyGenerateUnlinkedCodeBlockForFunctionExecutable) — this is the change from JSC: add a bytecode cache entry for UnlinkedFunctionExecutable #270, rebased onto main.
  • A depth parameter threaded through the recursive unlinked-code-block generators (generateUnlinkedCodeBlockForFunctions, recursivelyGenerate…ForProgram/ModuleProgram/FunctionExecutable) plus Options::bytecodeCacheMaxDepth (0 = top-level code block only, N = N levels of nested functions, -1 = unbounded, which stays the default so existing callers are unchanged). generateProgramBytecode / generateModuleBytecode honor the option, so bun build --bytecode can bound its blob size too.

Depth 0 turns out to be the right point for Bun's builtins: the whole corpus (194 modules, 2.5 MB source) encodes to 3.0 MB vs 12.0 MB fully recursive, and the parse it removes is almost entirely the whole-file parse of each module's top-level block.

Supersedes #270.

…ble cache entry

Adds a depth parameter to the recursive unlinked-code-block generators
(0 = top-level block only, N = N levels of nested functions,
default unbounded = previous behavior) and Options::bytecodeCacheMaxDepth,
on top of the CachedFunctionExecutable cache entry for function
executables (needed for builtin modules, which are compiled as
functions rather than programs).
@github-actions

github-actions Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

Preview Builds

Commit Release Date
2a84a42f autobuild-preview-pr-344-2a84a42f 2026-07-25 21:04:48 UTC
ca3163e7 autobuild-preview-pr-344-ca3163e7 2026-07-25 12:47:36 UTC
ab79200e autobuild-preview-pr-344-ab79200e 2026-07-25 12:01:14 UTC

Alignment padding in encoded pages was left as allocator garbage, which
made cache blobs vary byte-for-byte between runs. Zeroed pages make the
padding deterministic; a remaining ASLR-derived leak (a few words in a
handful of entries) is tracked separately.
HandlerInfoBase::typeBits was a 2-bit bitfield whose 30 padding bits
were never written, and UnlinkedHandlerInfo's default constructor left
start/end/target uninitialized. The exception-handler vector is
serialized bytewise into the bytecode cache, so cache blobs were not
reproducible (and carried stack garbage). Make typeBits a full-width,
default-initialized field and zero the rest of the default ctor.
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