Skip to content

AOT: large programs that run in several realms, and smaller runtime fixes - #1066

Draft
Jarred-Sumner wants to merge 15 commits into
mainfrom
claude/bun-desktop-framework-ntok56
Draft

Jarred-Sumner wants to merge 15 commits into
mainfrom
claude/bun-desktop-framework-ntok56

Conversation

@Jarred-Sumner

@Jarred-Sumner Jarred-Sumner commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Changes needed by Bun's experimental desktop programs.

Compiler

  • Order files record the regular expressions a run compiles, which then get native code.
  • New opt-in assumptions: separate-realms, locked-builtins, complete-order. Work in progress.

Run time

  • relaxTimingOfModuleLoads(): link and run a graph that is all in the image without the loader.
  • Remember the last extra key found, instead of walking the table for each new field.
  • Clear per-collection caches without reading untouched pages.
  • Read methods of String.prototype directly where realms share property caches.
  • A host whose global object lacks the host's names can say where it keeps them. Runtime flags leave SharedArrayBuffer and ShadowRealm out of a global object.

JavaScriptCore

  • drainMicrotasks() no longer spins while only suspended tasks are queued.
  • Set operations on character classes work on ranges instead of code points.
  • Build the lists of available locales with fewer calls into ICU.
  • Check for an exception after the scope lookup in the JSONP fast path.

Draft. After the merge with main, testaot and the stress, modules, es6 and complex collections (--quick) pass locally on a Linux x64 release build. For the latest commit, testaot and a subset of the stress and modules tests were run. Bun builds against it on Linux x64.

Known gaps

  • No test turns relaxed timing on, so it has not run since the latest merge, which changes module evaluation next to it.
  • The shortcut for locale lists has not been compared with the system ICU of macOS.
  • Regular expressions used only through a compiled matcher are not recorded, so complete-order can leave them without native code.
  • Order files contain the text of patterns.

Generated by Claude Code

…ixes

Changes needed by Bun's experimental desktop programs.

Compiler
- Visit each container once when exported built-ins escape; the walk was quadratic.
- Order files record the regular expressions a run compiles, which then get native code.
- New opt-in assumptions: separate-realms, locked-builtins, complete-order. Work in progress.

Run time
- relaxTimingOfModuleLoads(): link and run a graph that is all in the image without the loader.
- Remember the last extra key found, instead of walking the table for each new field.
- Clear per-collection caches without reading untouched pages.
- Read methods of String.prototype directly where realms share property caches.

JavaScriptCore
- drainMicrotasks() no longer spins while only suspended tasks are queued.
- Set operations on character classes work on ranges instead of code points.
- Build the lists of available locales with fewer calls into ICU.
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Preview build of 192a25b: autobuild-preview-pr-1066-192a25b0

…ions

- HeapCompaction: after a full collection, move cells out of sparse blocks. Off unless the embedder asks.
- separate-realms keeps the realm check for inlined foreign code and for files outside the project.
- locked-builtins respects spelled writes, unseen code and the debugger.
- complete-order is ignored unless the order file lists a regular expression.
- Patterns built at run time are only recorded on request; targets of import() and require() are recorded.

Copy link
Copy Markdown
Collaborator Author

bun-webkit-linux-amd64-lto-hardened-aot-no-webassembly fails on 5a7be28 because HeapCompaction.cpp reads Heap::m_pinballCompletionSpace, which only exists with ENABLE(WEBASSEMBLY). release is red because that lane's asset is missing. The other lanes and the test jobs passed.

The guard is written but not pushed: the branch conflicts with main in three files under aot/, so it will go up with that merge.

useHeapCompaction is off by default and should stay off. A review of it found a hang when no helper marker runs, quadratic time with many references to one object, and several ways a moved cell could be missed. It will be fixed or removed before this leaves draft.


Generated by Claude Code

It was off by default and is not ready: it can hang without helper markers, pauses
for seconds on arrays with many equal references, and can miss references.
With relaxed timing of module loads, imported CommonJS files keep running in the
order of their requests: filesInOrderOfSynchronousLoad() returns them as given.
main visits each container of the link flow once, so its version of
AOTLinkFlow and AOTLinkReach replaces the one on this branch.

Adds a test of set operations on wide ranges under the v flag.

Copy link
Copy Markdown
Collaborator Author

release failed on df708ee because the run was cancelled: bun-webkit-linux-arm64-android-aot never got past actions/checkout. Every other lane and all test jobs had passed. The run has been restarted.


Generated by Claude Code

Copy link
Copy Markdown
Collaborator Author

On the second attempt bun-webkit-macos-arm64 never got past actions/checkout, so nothing of it was compiled and release reports that one asset as missing. Every other lane and all test jobs passed, and the preview is published without it.


Generated by Claude Code

… a budget for Yarr

With more names than columns, the names that listed functions look up and the
fields of what they allocate get the columns. Argument thunks are placed by the
start rank of their first caller.

Reads through the global proxy cache custom accessors of the global object, and
pass an object that announces the names it makes up. Members of platform objects
with named properties are cached. With several realms, the stub finds the methods
of strings.

An inline cache no longer takes a name as absent below an object that may make it
up. A runtime flag hides callers of other realms from Function.prototype.caller.

Yarr can limit how far a pattern expands and how many steps a match takes.
… dispatch records

An embedder can publish the items of a list, with a clock that says how long they
hold. Inline caches, the slow path and the stubs of compiled programs read them
without asking the object.

A DOMJIT signature can take any value, and a DOMJIT getter needs no code of its
own. A function that can do anything is called directly only from its own realm.

Sites of compiled programs answer reads of a custom getter from its cached value.

TypedArray.prototype.set converts from left to right in a loop that can be
vectorized.

The table of built-ins has no dispatch record for a mode with one overload.
A host can mark an entry as optional. A build that the host says never comes by
those entries is compiled as if the table did not have them: their names are not
taken for names that a built-in answers, and nothing is kept on their account.
pauseIfNeeded never throws, but its ThrowScope simulated a throw when it
ended. Interpreter::debug checks for one. The way through VM::throwException
does not, so the code that threw failed the validation. No change without
ENABLE(EXCEPTION_SCOPE_VERIFICATION).

Jarred-Sumner commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator Author

Test bun-webkit-linux-arm64-lto failed on 6712c4c in one run: stress/embedder-list.js.ftl-eager-no-cjit, "expected 120, got 220". The test is from this branch. That assertion counts how often the list is asked once the code is compiled. The mode runs with --useExecutableAllocationFuzz --fireExecutableAllocationFuzzRandomly, where the allocation of code can fail, and the slower way asks the list every time. All values that were read are right. The next push leaves that one count out under this option. It waits for the release of this run, which a push would cancel.

Test bun-webkit-linux-arm64-lto-hardened has no failing test. The job ends with "this runner has no pointer authentication", so it is the runner that it got.


Generated by Claude Code

Jarred-Sumner pushed a commit to oven-sh/bun that referenced this pull request Nov 18, 2026
…skip size check]

The UI library and `bun compile --desktop` support Windows. The DevTools
protocol is served for pages and for the main process. WebGL 1 and 2 run on
Linux. Pages in processes of their own have service workers, shared workers,
WebGL and crash reports. Canvases on the CPU paint in batches on all cores.
`--desktop --trim` keeps what markup alone can reach. Fixes in text layout,
painting and context isolation. The pin of WebKit follows oven-sh/WebKit#1066.
…d; cheaper bind, join and rope resolution

A realm without a module host runs in the interpreter and borrows the
property tables of another realm's instance. Only own properties were
filed there, so each inherited method, accessor and absent name took
the slow path, and so did stores that add a property. They are filed
now, by the interpreter and by the lender's compiled code. The lender
keeps the records that drop them when a chain changes, so the tables are
cleared when a borrower outlives its lender. The global proxy of such a
realm is left out: the tables answer past the lookup of its host. What
is filed does not depend on the realm that asks first: Array.prototype
and the accessor of __proto__ are recognized in every realm.

With several realms, a read by name that met an object with a static
table that is not reified always called out. The stub now asks the
hashed table whether the name is absent from there on. For strings the
absence is filed under the structure of String.prototype.

keepChainDependent() hashed the name of a record whose entry, the only
owner of the name, could be gone.

Compiled stores to a var or let of a script, and to properties of a
global object that is somebody's prototype, called out each time. Their
location is filed now. The global object visits the variables of its
lexical environment, because such a store runs its barrier, and the
locations are dropped when a var becomes read-only. A host whose put()
has to see each store disables caching on the slot.

bind() of a bound function no longer reads its name and length while the
target has the Structure it was made with. join() counts a repeated
string before it asks for its characters. Resolving a rope no longer
takes the lock of the directory's bits, neither to see that the block is
destructible nor to mark it: the thread has access to the heap, and the
write is atomic.

embedder-list.js counts calls of the slow path, so it runs without
failing allocations of executable memory at random.
On x86-64 a type test in front of a nullish check loads through the
value and leaves everything that is no cell to the fault handler. With
four levels of page tables the address behind a boxed number is not
canonical, and Linux reports the fault at 0. With five levels it can be
canonical, and the fault comes with the address. The handler refused it,
so the process died with SIGSEGV where it reports the failed check.
@robobun

robobun commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

The three loops that languageTagForAvailableLocale() changes here are also in #1087. That PR makes each set at the first lookup of a locale, so a call that requests no locale makes none. The two merge without a conflict, and this helper then fills the sets.

One question about the helper. User instructions over an empty script (jsc, release, Linux x64, ICU 79.1):

first Intl.DateTimeFormat.supportedLocalesOf("en") uloc_toLanguageTag calls first new Intl.Segmenter()
main 12.2 million 907 12.6 million
this hunk 7.6 million 541 8.0 million
the same helper with a rule and no memo 1.5 million 2 1.9 million

With #1087 the last column is 0.46 million in each row.

The third row is 15206c7 (+70/-6 in IntlObject.cpp, no lock). It keeps the name of the helper and its three calls. It writes - for _ when the ID is a language, a script and a region, and asks ICU about every other ID (en_US_POSIX).

It takes ICU's answer for granted for 905 of the 906 IDs.

  • Checked: every ID of ICU 79.1's three lists, and of the lists in Apple's sources of ICU 66 to 76, converted with ICU 79.1. None has another tag.
  • Not checked: the ICU of a macOS. With icu: replace the C++ libraries with the parts that Bun uses, in Rust bun#49369 that is the one platform that keeps ICU4C's converter.
  • On that branch a test asks ICU about every listed ID and fails with the IDs that differ. A build with assertions checks each ID when a set is made.

Which of the two do you want in these loops? If it is the memo, nothing changes. If it is the rule, I open that commit as a pull request on top of #1087.

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