Repository navigation
fix(module): retain prepared ESM keys for equivalent paths - #83
Merged
Merged
Conversation
steipete
force-pushed
the
w94/windows-plugin-alias
branch
from
October 3, 2026 00:49
d7c7df6 to
6a52c0f
Compare
The synchronous loader re-resolved an already fetched absolute alias, linked a second spelling, and returned the original record with a null environment. Retain the prepared key during synchronous top-level resolution, preserving async plugin redirection and cache eviction.
Resolve normally and retain the prepared record only when filesystem URLs are equivalent. This preserves asynchronous alias identity while keeping real plugin redirects and cache eviction unchanged.
steipete
force-pushed
the
w94/windows-plugin-alias
branch
from
October 3, 2026 01:02
6a52c0f to
07a4f12
Compare
steipete
marked this pull request as ready for review
October 3, 2026 02:28
This was referenced Oct 3, 2026
steipete
added a commit
that referenced
this pull request
Oct 3, 2026
Repeated `node:vm` evaluations of large module graphs fall out of JavaScriptCore’s shared compilation cache near its 2,000-entry working set. This adds a bounded per-VM compilation cache, preserving fresh values and target globals while reusing context-independent bytecode across `Script`, `compileFunction`, and the run helpers. The cache activates after 1,750 distinct successfully compiled source fingerprints. Before activation, compilation takes the original JSC path followed by bounded fingerprint bookkeeping; it does not serialize or retain bytecode. Activation lasts for that VM’s lifetime. `BUN_VM_COMPILE_CACHE_THRESHOLD=0..2000` tunes admission (default 1750). `BUN_VM_COMPILE_CACHE_SIZE` sets a decimal byte budget (default 256 MiB per VM); **0 disables both caching and tracking**. Entries compare complete source text, filename/source URL, offsets, compilation kind/flags, lexical features, and dynamic-import callback identity. Explicit cachedData uses the existing validation path, and debugger/profiler modes bypass the layer. The byte LRU owns copied source/filename and immutable bytecode; decoded code and callbacks are weak references. The budget charges payloads, copied strings and a 1 KiB metadata reservation per entry. Allocator overhead, temporary encoding/decoding allocations and objects held by live Scripts/functions are outside this ownership budget. The bounded admission table is released at activation. No WebKit or dependency changes. ### Measured trade-off Linux c7a.24xlarge, captured async module wrappers, five randomized interleaved processes per size/runtime, eight passes per process; values are medians of process medians for passes 1–7. Main is 0731292. Node is 24.19.0. | Modules | Fork main ms | Candidate ms | Node ms | Retained Script ms | |---:|---:|---:|---:|---:| | 500 | 6.650 | 7.089 | 10.657 | 4.700 | | 1,500 | 28.555 | 28.445 | 27.283 | 21.653 | | 2,500 | 191.627 | 52.634 | 39.660 | 26.077 | | 4,000 | 371.403 | 85.099 | 63.355 | 35.211 | A fixed 20-pair follow-up at 500 measured **6.947 → 7.193 ms (+3.54%)**, with paired 95% bootstrap candidate/main bounds **1.011–1.054**: about **0.5 µs per compilation**. An initial paired run had approximately **256 KiB higher median peak RSS**; later RSS samples overlapped main. The cost is accepted in exchange for **72.5% and 77.1% shorter warm replay** at 2,500/4,000 modules, where measured consumer files’ roughly 2,100-module graphs encounter pruning. Candidate/main timing bounds at those sizes are 0.272–0.280 and 0.228–0.232. Each interval uses 20,000 process-level bootstrap samples. The candidate remains **32.7% slower than Node at 2,500** and **34.3% slower at 4,000**. Node parity is not claimed. Main/candidate median process peak RSS in the five-run grid is 129,312/130,464 KiB at 500, 336,048/336,512 at 1,500, 873,540/863,280 at 2,500, and 1,530,288/1,374,156 at 4,000. These measurements are workload-specific. ### Validation The implementation passes 352 Bun VM tests (3 existing skips, 60 existing TODOs), 102/102 ported Node parallel/sequential VM tests, and an identical Node 24 semantic probe. New coverage checks admission, cache keying, stack traces and offsets, cached errors/data, fresh values/contexts, import identities, byte eviction/recency, and decoded-code lifetime. A parser-trace regression fails on unpatched Bun and passes with reuse after GC. Scoped-clean P2 review completed on head `17ec8b2453db2a4bd844b561884ba5d3be0b92c0` against merge base `3d1c40b8b39e4377a773b26d57440fdbc69bf0b0`. Both fork native CI lanes pass on that exact head: [run 37090421840](https://github.com/openclaw/bun/actions/runs/37090421840). Darwin required one unchanged retry after an existing wall-clock timeout assertion missed its first deadline; the isolated case also passed unchanged. No test assertion was weakened. Formatting, source lint and JavaScript lint pass. The ancillary duplicate-PR bot cannot start because its authentication is not configured. The final cold consumer matrix passed on OpenClaw main **ff96d47c3506c50123a555332e6a6cc576b2559f** (Vitest 5.0.1). Main Bun is **3d1c40b8b39e4377a773b26d57440fdbc69bf0b0**; candidate is **17ec8b2453db2a4bd844b561884ba5d3be0b92c0**. Node is 24.19.0. Each config/runtime has **five interleaved cold runs** on one AWS c7a.24xlarge lease: 30 arms, three pinned four-CPU slots, fresh filesystem overlays and compilation/transform caches, private HOME/state and short 0700 TMPDIRs. Both configs use four thread workers with `isolate:false`. No dependency changes. | Config | Runtime | Median / p95 seconds | Median / maximum peak RSS GiB | |---|---|---:|---:| | auto-reply-reply | node | 238.48 / 240.31 | 10.951 / 11.322 | | auto-reply-reply | main | 232.17 / 246.83 | 17.250 / 17.860 | | auto-reply-reply | patched | 226.22 / 227.26 | 17.720 / 18.430 | | extension-discord | node | 106.80 / 108.34 | 7.638 / 8.039 | | extension-discord | main | 140.23 / 147.14 | 17.631 / 18.559 | | extension-discord | patched | 124.99 / 132.25 | 17.550 / 18.043 | Candidate/main median ratios (20,000 process-level bootstrap resamples): - **auto-reply-reply: 0.9744**, 95% interval **0.9048–0.9987**. - **extension-discord: 0.8913**, 95% interval **0.8399–0.9461**. Every file and every assertion name/status matches across all fifteen runs of each config: **Discord 264 files, 3,187 passes, zero skips; auto-reply 233 files, 4,317 passes, one existing skip; zero failures**. All 30 invocations exited successfully, published complete reports and left no namespace descendants. The three broker-dependent files also pass identically in their existing fork-based infra owner (27 assertions). **Consumer trade-off:** Discord median time improves 10.9%; auto-reply improves 2.6%. Auto-reply median peak RSS rises 2.7% (17.25 → 17.72 GiB); Discord RSS is essentially unchanged (17.63 → 17.55 GiB). Both RSS ratio intervals overlap 1. The candidate remains 17.0% slower than Node on Discord, while auto-reply is 5.1% faster than Node. Node uses substantially less RSS in both configs. The p95 is interpolated from five process observations. RSS is GNU time’s process/descendant high-water metric, not an aggregate cgroup measurement. Cold means fresh application caches/process state, not an OS page-cache flush. These bounds describe this host/workload. The microbenchmark constructs wrappers without executing module bodies; consumer runs include evaluation and test work, so their percentage gains differ. Main advanced with #83 during the first matrix. The branch was rebased, both binaries rebuilt, and the entire 30-arm matrix restarted on the same lease. The interrupted old-baseline samples are preserved separately and excluded from the final cohort. ### Engine follow-up Upstream searches found related cached-data work, including oven-sh#41769, but no ordinary-compilation working-set fix to port. No upstream PR is being opened in this round. This may be useful upstream after broader evaluation; no upstream acceptance is implied. Future engine support could provide (1) an exported retained-size/growth contract for complete unlinked-code graphs, including nested code, profile data and JIT allocations; or (2) ownership references that let decoders borrow storage safely from evictable owned bytecode. Either could reduce copying/decoding cost and needs independent lifetime and performance proof. The runtime docs describe the controls, bounds and measured trade-off; the changelog addition is append-only.
This was referenced Oct 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requiring an ESM alias whose absolute path uses forward slashes on Windows can crash when reading its first export. A
/./path segment reproduces the same bug on macOS without native addons or application dependencies. BothBun.plugin().onResolveandModule._resolveFilenameoverrides can trigger it.The CommonJS handoff prepares a record under the returned key. Top-level resolution can change the spelling and link a second record, while
requireESMreturns the original record's namespace with a null environment. The Windows fault resolves toJSC::getValue +0x13, reading address0x18.Run resolution normally, then retain the prepared record when the filesystem URLs are equivalent. Real plugin redirects still select their new target. This preserves alias import/require identity and async redirect/cache-eviction behavior without a WebKit change. Upstream: oven-sh#44482.
Fork PR CI has Linux and macOS lanes and no Windows lane. Native Windows Server 2022 qualification used Node 24.21.0 as oracle:
6a5d9c721f07a4f1202e0x18Every previously passing assertion and every envelope exit status is preserved, with no unhandled-error increases and no native panics. Assertion identities, including duplicate occurrences, are unchanged. The five newly executed failures were previously pending: two path-spelling comparisons are independently reproduced unchanged on both old and patched Bun (both normalize to the expected file), and three directory-cleanup cases also fail under Node/W83. These remain reported failures. The environment fix in #81 accounts for the other improvement. All 32 envelopes completed in 1,899.761 seconds; 23 have exit status zero.
The focused environment and stdio fixtures also pass on this combined binary. Locally, the surrounding plugin/module/require-cache suites pass 661 tests (one skip, one todo); the local integration passes 48 focused tests (four platform skips) and OpenClaw lazy-alias 24/24 on macOS. The local integration and final candidate have identical complete Git trees.
Unpublished build 37084505411 passed cross-build, native Windows smoke, and manifest; Publish was skipped. ZIP SHA-256:
0432a57a259f305d0c182f86e561747e2a9191a6fba0079db259a5deeeb58db6; executable SHA-256:c53ddd3b5f8fc31048ff7f8443739c621fbb8c44af029e6d4e5048fb206864e6. Both matched locally and on the native lease. The executable is unsigned and was not published.Linux/macOS CI passes on exact head
07a4f1202ea2c2a270a9709898b8ba5803586b9din 37084508540; final branch P2 review is scoped-clean. The unrelated Claude duplicate-finder action fails because its provider credentials are not configured.