Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d9e9626
AOT: module binding, class fields, unused classes, names of modules o…
Jarred-Sumner Oct 28, 2026
5a23339
AOT: the kind of a module goes by its text, getters that read a name …
Jarred-Sumner Oct 28, 2026
0468a4a
AOT: fixes, tests and shorter docs; WebKit d6e9f85e [skip size check]
Jarred-Sumner Oct 28, 2026
6e3f36f
AOT: tests as small files in the ordinary shards; WebKit preview-pr-9…
Jarred-Sumner Oct 28, 2026
380e8dd
[autofix.ci] apply automated fixes
autofix-ci[bot] Oct 28, 2026
361c50d
scripts/runner.node.ts is executable [skip size check]
Jarred-Sumner Oct 28, 2026
43169b1
AOT: library modules held as values, typed parses keep declared types…
Jarred-Sumner Oct 28, 2026
9f3242a
AOT: test programs build at default flags and share builds; a Worker …
Jarred-Sumner Oct 28, 2026
5319f52
[autofix.ci] apply automated fixes
autofix-ci[bot] Oct 28, 2026
b4ba001
AOT: the test driver runs programs before it builds more and removes …
Jarred-Sumner Oct 28, 2026
33622b9
AOT: on Linux the test files that build many executables run on the B…
Jarred-Sumner Oct 28, 2026
04b9307
AOT: the ELF and Linux writers hand out owned parts of a mapping; a f…
Jarred-Sumner Oct 28, 2026
add8dde
[autofix.ci] apply automated fixes
autofix-ci[bot] Oct 28, 2026
184e0b8
AOT: a program is compiled once where library code was lacking; a bui…
Jarred-Sumner Oct 28, 2026
d997b76
AOT: test programs that took long share one library; five sweeps over…
Jarred-Sumner Oct 28, 2026
8b2f312
AOT: native code that lists the environment counts as a caller of its…
Jarred-Sumner Oct 28, 2026
aaab6c8
AOT: each program of an executable holds the module of the library th…
Jarred-Sumner Oct 28, 2026
e522379
AOT: what the table of built-ins only guesses is left to the engine t…
Jarred-Sumner Oct 28, 2026
d78b7d5
AOT: a module object handed to native code is listed among the forms …
Jarred-Sumner Oct 28, 2026
6af52b8
AOT: the options of Bun.spawn, Bun.listen, Bun.connect and fetch are …
Jarred-Sumner Oct 28, 2026
6fd51bb
AOT: the bounds on instructions a turn hold on the lane that counts t…
Jarred-Sumner Oct 28, 2026
8a44e04
AOT: WebKit f495db1d; with AddressSanitizer the test files of the com…
Jarred-Sumner Oct 28, 2026
6e63b62
Merge branch 'main' into claude/compile-aot-on-check [skip size check]
Jarred-Sumner Oct 28, 2026
c5e86e6
AOT tests: one build-scaling shape has its growth in memory in its row
Jarred-Sumner Oct 28, 2026
da05b24
Merge branch 'main' into claude/compile-aot-on-check
Jarred-Sumner Oct 28, 2026
021911d
AOT: exception checks at the call sites in BunProcess.cpp; tests of n…
Jarred-Sumner Oct 28, 2026
92276be
Remove the system CA certificate prefetch from standalone executables
Jarred-Sumner Oct 29, 2026
5f5f865
Remove the macOS tests for the system CA certificate prefetch
Jarred-Sumner Oct 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
version=$(sed -n 's/^export const WEBKIT_VERSION = "\(.*\)";$/\1/p' scripts/build/deps/webkit.ts)
git init --quiet "$RUNNER_TEMP/WebKit"
git -C "$RUNNER_TEMP/WebKit" remote add origin https://github.com/oven-sh/WebKit.git
git -C "$RUNNER_TEMP/WebKit" sparse-checkout set Source/JavaScriptCore
git -C "$RUNNER_TEMP/WebKit" sparse-checkout set Source/JavaScriptCore Tools/Scripts/aot
git -C "$RUNNER_TEMP/WebKit" fetch --quiet --depth=1 --filter=blob:none origin "refs/tags/autobuild-${version#autobuild-}"
git -C "$RUNNER_TEMP/WebKit" checkout --quiet FETCH_HEAD
BUN_WEBKIT_PATH="$RUNNER_TEMP/WebKit" bun test test/internal/build-aot-codegen-declared-outputs.test.ts -t "finds a use for every name of the schema"
Expand Down
5 changes: 2 additions & 3 deletions docs/compiler/aot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ curl localhost:3000/todos/1

### The typed percentage

After the `compile` line, the build prints how much of your program is typed. These lines are from a larger program.
Untyped code works, but runs slower. `bun compile --explain` prints how much of your program is typed, in the last lines of its report. These lines are from a larger program.

```txt
Untyped code works, but runs slower. Run with --explain to see what to fix.
Dependencies: 3.1% of property accesses are one load: 210 free, 1,320 tested, 5,244 by name (6,774)
92.4% of property accesses are one load: 1,204 free, 61 tested, 38 by name (1,303)
```
Expand All @@ -117,7 +116,7 @@ Code in `node_modules` is counted separately, on its own `Dependencies:` line.

The todo server only has a handful of property accesses, and most of them are of the last kind, so its percentage is low. That doesn't mean much for a program this small. A lookup by name only matters in hot code. There, read the property once and keep the value in a variable.

Under 95%, Bun also prints the hint about `--explain`. `bun compile --explain` lists what's lowering the number, worst first, with a fix for each. [Get more of your program typed](/compiler/explain) explains exactly what is counted and how to work through the list.
The rest of the report lists what's lowering the number, worst first, with a fix for each. [Get more of your program typed](/compiler/explain) explains exactly what is counted and how to work through the list.

### Type errors stop the build

Expand Down
27 changes: 18 additions & 9 deletions docs/compiler/compatibility.mdx

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions docs/compiler/explain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ description: "What the typed percentage counts, how to read bun compile --explai

<Warning>Ahead-of-time compilation is experimental.</Warning>

[`bun compile`](/compiler/aot) ends with the percentage of your program's property accesses that are typed.
The report of [`bun compile --explain`](/compiler/aot) ends with the percentage of your program's property accesses that are typed. A build without `--explain` doesn't print it.

```txt
Untyped code works, but runs slower. Run with --explain to see what to fix.
75% of property accesses are one load: 6 free, 1 tested, 1 by name (8)
```

A typed access is one load or one store at a fixed offset. An untyped access runs a test of its own first, or looks the property up by name at run time. The higher the number, the faster the executable. How much faster depends on the program.

`bun compile --explain` lists what's lowering the number, worst first. Each entry has the line where the missing type begins, a fix, and what hangs on that line: property accesses, indirect calls and untyped operators, with an estimate of how much of the run time they take.
Above that line, the report lists what's lowering the number, worst first. Each entry has the line where the missing type begins, a fix, and what hangs on that line: property accesses, indirect calls and untyped operators, with an estimate of how much of the run time they take.

## What is counted

Expand Down Expand Up @@ -77,7 +76,7 @@ Dependencies: 3.1% of property accesses are one load: 210 free, 1,320 tested, 5,
92.4% of property accesses are one load: 1,204 free, 61 tested, 38 by name (1,303)
```

Bun rounds down, so 100% means every access. `--explain` then has nothing to report about your own code. Bun prints the hint about `--explain` when the number for your own code is under 95%.
Bun rounds down, so 100% means every access. `--explain` then has nothing to report about your own code.

## Read an entry

Expand Down Expand Up @@ -214,22 +213,22 @@ console.log(total);
```

```bash terminal icon="terminal"
bun compile ./main.ts
bun compile ./main.ts --explain
```

```txt
33.3% of property accesses are one load: 1 free, 0 tested, 2 by name (3)
```

Every `Item` in the list is now an object literal that the compiler sees, so `item.price` in the loop is free. The two accesses that are left are in `readItem`. It reads `sku` and `price` from the parsed object by name, once for each object that comes in.
That's the last line of the report. Every `Item` in the list is now an object literal that the compiler sees, so `item.price` in the loop is free. The two accesses that are left are in `readItem`. It reads `sku` and `price` from the parsed object by name, once for each object that comes in.

Fix the first entry, then run the command again. A fix can uncover another cause behind it: if two things keep `Item` untyped, the report shows one of them at a time.

`bun check --aot --explain` prints the same report and writes no executable.

## After the entries

The report ends with the numbers behind the percentage. These are from a larger program.
After the entries come the numbers behind the percentage, then the percentage itself. These are from a larger program.

```txt
note: All property accesses, including dependencies:
Expand All @@ -246,12 +245,15 @@ Files with the most untyped accesses:
and 3 more
Compiler limits hit:
MaxLayoutsInType = 1,024, hit 2 times (limits object shapes in one inferred type)
Dependencies: 3.1% of property accesses are one load: 210 free, 1,320 tested, 5,244 by name (6,774)
92.4% of property accesses are one load: 1,204 free, 61 tested, 38 by name (1,303)
```

- **The first three numbers** are the [three ways](#what-is-counted) to compile an access, for your code and your dependencies together.
- **`Calls`** counts calls of functions and methods, except the built-in functions that Bun resolves at build time. A call is direct if the compiler knows the callee. An indirect call finds it at run time.
- **`Files with the most untyped accesses`** lists up to five of your own files.
- **`Compiler limits hit`** lists the limits this build ran into, and how often. Past a limit the compiler assumes less, so some accesses may be untyped because of it. See [limit-reached](#limit-reached).
- **The last two lines** are the percentage: one line for your dependencies, if they have property accesses, and one for your own code.

## JSON

Expand Down
5 changes: 3 additions & 2 deletions docs/compiler/internals.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ bun compile --aot-log-type-mismatches ./dot-declared.ts && ./dot-declared '{"vec
[aot] type-mismatch d410bc586c26 variable dot-declared.ts:11:31 (module): expected { vec }, got untyped object; continued; count 1
```

So the parser checks nothing for you, and the type stays a prediction. The reads behind it are loads from slots, behind tests that pass. The build's summary counts them as `tested`, not as `free`.
So the parser checks nothing for you, and the type stays a prediction. The reads behind it are loads from slots, behind tests that pass. `--explain` counts them as `tested`, not as `free`.

`JSON.parse(text) as { vec: Vec }` does the same as the annotation, and so does passing the result straight to a typed parameter. The table of built-ins marks the calls that can take a parser this way with `typedResultForm`: `JSON.parse`, the `json()` of a `Request`, a `Response` or a `Blob`, and the rows of a `Bun.sql` query.

Expand Down Expand Up @@ -1047,6 +1047,7 @@ A wrong effect is a miscompile, so effects aren't taken on faith.
- An operation that `replaces` others may do no more than they do. `aot/tests/ir/effects/check-replacement*.ir` has the cases.
- `checkDeclaredEffects()` and `checkEffectSummaries()` compare what the rules compute with the declared bounds in a validating build.
- With `--aot-validate`, a call of native code that's declared not to collect, not to throw, not to write a heap or not to keep an operand is checked at run time. These are some of the failures it can report, from `aot/ir/schema/runtime-records.def`: `NativeCallChangedOperand`, `NativeCallWroteHeap`, `NativeCallRanCode`, `NativeCallThrew`, `NativeCallCollected`, `NativeCallKeptOperand`, `BarrierWasNeeded`.
- A call that's said not to throw, not to be terminated and not to run other code has no site, and a handler is found by the site of the call that a throw leaves. With `--aot-validate`, the compiler puts a mark in the code after every call without a site, and a throw that leaves such a call is reported before it's unwound: `CallThrew`, with the function, the value and the operation or stub that was called.

## Built-ins

Expand Down Expand Up @@ -2059,7 +2060,7 @@ These flags have no entry in `--help`. They exist for working on the compiler.

| Term | Meaning |
| ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| Access, `free` / `tested` / `by name` | The three states of a property access in the build's summary: one load, a test and a load, a lookup |
| Access, `free` / `tested` / `by name` | The three states of a property access in the counts of `--explain`: one load, a test and a load, a lookup |
| Cage | The 32 GB reservation that holds the cells of one VM, so that a reference fits in 32 bits |
| Check | An IR operation that asks for a value to have a type. Flow answers it, or it becomes a type test |
| Closed world | The assumption that the image is all the code that will ever run in the process |
Expand Down
2 changes: 1 addition & 1 deletion docs/compiler/troubleshooting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Where `bun run` quotes your source in a message, as in `null is not an object (e

Startup and memory improve for every server in [What to expect](/compiler/aot#what-to-expect). Requests per second go up for some and down for others. Look for these causes, in this order.

**Most of the hot code is untyped code from npm.** The `Dependencies:` line at the end of a build has their share, and `bun compile --explain` lists the causes. The count of an entry that only affects dependencies ends with `in dependencies`.
**Most of the hot code is untyped code from npm.** `bun compile --explain` lists the causes, and the `Dependencies:` line at the end of the report has their share. The count of an entry that only affects dependencies ends with `in dependencies`.

```txt
Dependencies: 0% of property accesses are one load: 0 free, 0 tested, 2 by name (2)
Expand Down
40 changes: 24 additions & 16 deletions scripts/aot-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const testsThatComeInParts = [
/** These read the engine's sources, which no test machine has. .github/workflows/lint.yml runs them. */
export const testsOfEngineSources = [
"aot/a-switch-of-the-compiler-names-every-enumerator.test",
"aot/any-two-sources-of-the-compiler-can-share-a-translation-unit.test",
"aot/emitters-append-in-the-order-written.test",
"aot/engine-types-are-defined-once.test",
"aot/every-field-of-flows-results-is-written-and-read.test",
Expand All @@ -110,6 +111,7 @@ export const testsOfEngineSources = [
"aot/lists-of-operations-in-the-compiler-only-shrink.test",
"aot/one-text-of-the-engine-reads-what-a-descriptor-literal-says.test",
"aot/the-compiler-reads-no-environment-variable.test",
"aot/the-compiler-sorts-with-its-own-sort.test",
"aot/the-frame-of-an-operation-outlives-whoever-is-handed-its-address.test",
"aot/the-value-under-a-chain-of-casts-is-only-asked-about.test",
"aot/what-is-only-expected-of-a-position-is-widened-in-one-place.test",
Expand Down Expand Up @@ -181,6 +183,9 @@ export function getAotAlwaysDrawn(
"aot/without-executable-memory",
// Each system has its own way to take a wish for an address.
"aot/every-launch-places-its-heap-anew",
// Each system has its own way to tell a process its time zone, and its own folders above a temporary one.
"aot/time-zone-at-start",
"aot/plain-bun-installs-no-packages",
// Only on this CPU is the reach of a call within the size of a large program.
...(arch === "aarch64" ? ["aot/calls-beyond-their-reach"] : []),
// Only a file system that ignores the case of letters can tell it from any other resolution.
Expand All @@ -203,24 +208,30 @@ export function getAotAlwaysDrawn(
export const testsAwaitedOn: Record<string, string[]> = {
windows: [
"aot/a-descriptor-that-is-written-out-is-no-object-whatever-it-describes-a-property-of",
"aot/an-operation-without-a-value-stops-the-build",
"aot/code-nested-in-itself",
"aot/a-field-that-holds-undefined-outside-the-cell-fails-no-test",
"aot/asking-about-a-class-keeps-none-of-its-code",
"aot/compact-code-avoids-runtime",
"aot/engine-tests-ir",
"aot/engine-tests-native",
"aot/every-program-28.",
"aot/every-program-3.",
"aot/every-program-alone-82.",
"aot/every-program-alone-39.",
"aot/every-program-alone-60.",
"aot/function-prototypes.",
"aot/in-place-executables.",
"aot/minifying-first-saves-no-code-12.",
"aot/one-line-changes-little-1.",
"aot/pointers-into-what-a-cell-owns",
"aot/programs-in-every-run-18.",
"aot/programs-in-every-run-29.",
"aot/programs-in-every-run-31.",
"aot/programs-in-every-run-13.",
"aot/programs-in-every-run-23.",
"aot/programs-in-every-run-25.",
"aot/programs-in-every-run-27.",
"aot/programs-in-every-run-37.",
"aot/programs-in-every-run-46.",
"aot/programs-in-every-run-49.",
"aot/programs-in-every-run-59.",
"aot/workers-from-embedded-files",
"aot/workers-from-texts-that-the-build-knows",
"aot/workers-named-by-relative-texts",
"aot/programs-in-every-run-44.",
"aot/programs-in-every-run-60.",
"aot/runtime-counts-file",
"aot/the-runner-of-workers-writes-its-line-into-a-stream-that-a-worker-has-filled",
"aot/wide-prototype-objects-cost-what-narrow-ones-cost",
"bundler/compile-trim-remove",
],
};

Expand All @@ -230,9 +241,6 @@ export function getAotAlwaysInDrawnStep({ os, profile }: AotLane, aot: AotTests)
...(testsAwaitedOn[os] ?? []),
// A mark for this lane alone can only be found stale on this lane.
...(aot === "all" ? ["aot/programs-marked-as-failing"] : []),
// Each system has its own way to tell a process its time zone, and its own folders above a temporary one. They go to the other step once they have been green here.
"aot/time-zone-at-start",
"aot/plain-bun-installs-no-packages",
// They go to the other step once they have been green here.
...(profile === "asan" ? testsWithSanitizer : []),
// One test of the first is for this system, and the file system ignores the case of letters. They go to the other step once they have been green here.
Expand Down
Loading
Loading