From 43d4f4cd492e489f75aeacbc161b1e328268a608 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 4 Oct 2026 19:11:29 -0700 Subject: [PATCH 1/5] perf: cache stack coordinates and defer typed array byte summation --- JSTests/stress/array-buffer-accounting.js | 26 +++++++++++++++++ .../stack-position-regressions-cache.js | 20 +++++++++++++ OPENCLAW.md | 14 ++++++++++ .../JavaScriptCore/dfg/DFGSpeculativeJIT.cpp | 4 --- Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp | 2 -- Source/JavaScriptCore/heap/Heap.cpp | 28 +++++++++++++++---- Source/JavaScriptCore/heap/Heap.h | 9 +++--- .../JavaScriptCore/parser/SourceProvider.cpp | 9 ++++-- Source/JavaScriptCore/parser/SourceProvider.h | 5 +++- 9 files changed, 98 insertions(+), 19 deletions(-) create mode 100644 JSTests/stress/stack-position-regressions-cache.js diff --git a/JSTests/stress/array-buffer-accounting.js b/JSTests/stress/array-buffer-accounting.js index 81563bb56c98e..c5aa645308af1 100644 --- a/JSTests/stress/array-buffer-accounting.js +++ b/JSTests/stress/array-buffer-accounting.js @@ -175,3 +175,29 @@ var modeSharedView = new Uint8Array(modeShared); modeShared.grow(32); equal(modeSharedView.length, 32, "grown shared auto length"); equal(modeSharedView[24], 0, "grown shared indexed bounds"); + +// Read fresh allocations after materializing an old view, and collect a prefix +// that has never been inspected. Neither operation may lose or double its bytes. +var deferredViews = [allocate(37)]; +fullGC(); +var deferredBefore = memoryUsage().arrayBuffers; +for (var i = 0; i < 64; ++i) + deferredViews.push(allocate(17)); +deferredViews[0].buffer; +equal(memoryUsage().arrayBuffers, deferredBefore + 64 * 17, "old materialization with a fresh prefix"); +for (var i = 0; i < 64; ++i) + deferredViews.push(allocate(17)); +edenGC(); +equal(memoryUsage().arrayBuffers, deferredBefore + 128 * 17, "uninspected live prefix after eden"); +deferredViews.push(allocate(0)); +deferredViews[deferredViews.length - 1].buffer; +equal(memoryUsage().arrayBuffers, deferredBefore + 128 * 17, "empty materialization"); +fullGC(); +var uninspectedBefore = memoryUsage().arrayBuffers; +temporary = []; +garbage(); +temporary = null; +fullGC(); +equal(memoryUsage().arrayBuffers, uninspectedBefore, "uninspected dead prefix after full GC"); +deferredViews.push(allocate(19)); +equal(memoryUsage().arrayBuffers, uninspectedBefore + 19, "allocation after prefix reclamation"); diff --git a/JSTests/stress/stack-position-regressions-cache.js b/JSTests/stress/stack-position-regressions-cache.js new file mode 100644 index 0000000000000..0b726ce007362 --- /dev/null +++ b/JSTests/stress/stack-position-regressions-cache.js @@ -0,0 +1,20 @@ +// Exercise cached offsets from independent providers, including equal offsets +// with different line tables, UTF-16 columns, and compressed-table boundaries. +const sources = []; +for (const terminator of ["\n", "\r\n", "\u2028", "\u2029"]) { + for (const lines of [0, 1, 63, 64, 65, 127]) { + const prefix = "/* 🦞 */ "; + const body = prefix + "(function positionCacheProbe() { return new Error('cache'); })"; + const source = terminator.repeat(lines) + body; + sources.push({ create: eval(source), line: lines + 1, column: body.indexOf("new Error") + 1 }); + } +} +for (let repeat = 0; repeat < Math.min(testLoopCount, 30); ++repeat) { + for (const { create, line, column } of sources) { + const stack = create().stack; + const firstFrame = stack.split("\n").find(frame => /:(\d+):(\d+)\)?$/.test(frame)); + const match = /:(\d+):(\d+)\)?$/.exec(firstFrame); + if (!match || Number(match[1]) !== line || Number(match[2]) !== column) + throw new Error(`Expected ${line}:${column}, got ${stack}`); + } +} diff --git a/OPENCLAW.md b/OPENCLAW.md index eabfbe42bab60..4b0f3e63a655f 100644 --- a/OPENCLAW.md +++ b/OPENCLAW.md @@ -142,6 +142,8 @@ baseline. Engine and Bun headers and libraries must be rebuilt together. ## Unreleased +- Cache source-relative stack line and column lookups on demand, including syntax-selected positions. +- Defer FastTypedArray byte summation until inspection, materialization, or collection while retaining exact worker snapshots. - Keep syntax-selected stack positions separate from exception ranges for calls, constructors, property reads, and async continuations. Preserve the positions across bytecode rewriting, optimization, and cache replay. - Add real byte-based JSC heap allocation sampling with weighted allocating-stack profiles and independent major/minor collection inclusion. @@ -156,3 +158,15 @@ baseline. Engine and Bun headers and libraries must be rebuilt together. `CodeBlock::callSitePositionForBytecodeIndex` returns an optional absolute source offset for an exact instruction or async resume label. Stack readers use this position while exception expression ranges and debugger line tables retain their existing divots. RareData owns the two sparse vectors, including decoded cache entries; the bytecode cache revision prevents older layouts from being reused. Bun must be rebuilt with its matching stack-reader adapter. It must also preserve built-in error constructor syntax: rewriting `new Error()` as `Error()` changes the position and allows a returning arrow to become a proper tail call. The engine's proper-tail-call behavior is unchanged. The integration continues @robobun’s upstream Bun source-position work in [#35179](https://github.com/oven-sh/bun/pull/35179), [#37396](https://github.com/oven-sh/bun/pull/37396), and [#41580](https://github.com/oven-sh/bun/pull/41580). + +The source provider caches only requested line/column conversions under its existing +line-table lock. Coordinates remain relative to the provider's text; document +offsets and builtin provider overrides retain their existing behavior. Nothing is +computed at throw time or added to the persistent bytecode-cache format. + +Unmaterialized typed-array views remain in the VM-owned weak list. Allocations +prepend their views without updating a second byte counter. Statistics and +materialization sum only the prefix added since the last observation, and collection +accounts surviving new views while pruning dead ones. All reporting still runs on +the owning VM thread, including busy and parked workers; it never returns a deferred +estimate. Materialized backing stores retain their cross-thread atomic accounts. diff --git a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp index 195f2e4a30541..0d3534fb32b1e 100644 --- a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp +++ b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp @@ -11679,10 +11679,6 @@ void SpeculativeJIT::emitNewTypedArrayWithSizeInRegister(Node* node, TypedArrayT or64(TrustedImm64(JSArrayBufferView::fastModeBits()), scratchGPR); store64(scratchGPR, Address(resultGPR, JSArrayBufferView::offsetOfModeAndNext())); storePtr(resultGPR, Address(scratchGPR2)); - move(sizeGPR, scratchGPR); - lshiftPtr(TrustedImm32(logElementSize(typedArrayType)), scratchGPR); - move(TrustedImmPtr(vm().heap.addressOfUnmaterializedArrayBufferBytes()), scratchGPR2); - add64(scratchGPR, Address(scratchGPR2)); #else store8(TrustedImm32(FastTypedArray), Address(resultGPR, JSArrayBufferView::offsetOfMode())); #endif diff --git a/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp b/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp index 6f40c3f064f3f..a17aff55abfe7 100644 --- a/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp +++ b/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp @@ -11359,12 +11359,10 @@ IGNORE_CLANG_WARNINGS_END #endif #if USE(BUN_JSC_ADDITIONS) auto listAddress = m_out.absolute(vm().heap.addressOfUnmaterializedArrayBufferViews()); - auto bytesAddress = m_out.absolute(vm().heap.addressOfUnmaterializedArrayBufferBytes()); auto modeAndNext = m_out.bitOr(m_out.loadPtr(listAddress), m_out.constInt64(JSArrayBufferView::fastModeBits())); // The packed store initializes mode too, so mode loads must alias it. m_out.storePtr(modeAndNext, m_out.address(m_heaps.JSArrayBufferView_mode, fastResultValue, JSArrayBufferView::offsetOfModeAndNext())); m_out.storePtr(fastResultValue, listAddress); - m_out.storePtr(m_out.add(m_out.loadPtr(bytesAddress), byteSizeWithoutAdjustment), bytesAddress); #else m_out.store32As8(m_out.constInt32(FastTypedArray), fastResultValue, m_heaps.JSArrayBufferView_mode); #endif diff --git a/Source/JavaScriptCore/heap/Heap.cpp b/Source/JavaScriptCore/heap/Heap.cpp index f39cd6d5cd522..06d8df4cb2a12 100644 --- a/Source/JavaScriptCore/heap/Heap.cpp +++ b/Source/JavaScriptCore/heap/Heap.cpp @@ -1100,7 +1100,7 @@ size_t Heap::objectCount() size_t Heap::arrayBufferSize() { #if USE(BUN_JSC_ADDITIONS) - return allocatedArrayBufferSize() + m_unmaterializedArrayBufferBytes; + return allocatedArrayBufferSize() + unmaterializedArrayBufferSize(); #else return m_arrayBuffers.size(); #endif @@ -1112,7 +1112,18 @@ void Heap::addUnmaterializedArrayBufferView(JSArrayBufferView* view) ASSERT(!view->hasArrayBuffer()); view->setNextUnmaterializedView(m_unmaterializedArrayBufferViews); m_unmaterializedArrayBufferViews = view; - m_unmaterializedArrayBufferBytes += view->byteLengthRaw(); +} + +size_t Heap::unmaterializedArrayBufferSize() const +{ + // Inspections run on the owning VM thread. Only allocations since the last + // inspection, materialization or collection need to be added to its total. + for (auto* view = m_unmaterializedArrayBufferViews; view != m_accountedUnmaterializedArrayBufferViews; view = view->nextUnmaterializedView()) { + ASSERT(!view->hasArrayBuffer()); + m_unmaterializedArrayBufferBytes += view->byteLengthRaw(); + } + m_accountedUnmaterializedArrayBufferViews = m_unmaterializedArrayBufferViews; + return m_unmaterializedArrayBufferBytes; } void Heap::didAllocateArrayBufferAuxiliaryMemory(Subspace* subspace, size_t bytes) @@ -1137,7 +1148,7 @@ size_t Heap::externalMemorySizeForReporting() { return m_nativeExternalMemoryAfterLastCollection + (m_nonArrayBufferBytesAllocated - m_nonArrayBufferBytesAllocatedAtLastCollection) - + heldArrayBufferSize() + m_unmaterializedArrayBufferBytes + arrayBufferObjectSize(); + + arrayBufferPayloadSize() + arrayBufferObjectSize(); } size_t Heap::jsHeapSizeForReporting() @@ -3204,20 +3215,27 @@ void Heap::sweepArrayBuffers() // Surviving views are old after each sweep. Eden cannot reclaim that suffix. auto* end = collectionScope() == CollectionScope::Full ? nullptr : m_oldUnmaterializedArrayBufferViews; auto* view = m_unmaterializedArrayBufferViews; + bool isUnaccounted = true; while (view != end) { + if (view == m_accountedUnmaterializedArrayBufferViews) + isUnaccounted = false; auto* next = view->nextUnmaterializedView(); if (view->hasArrayBuffer() || !isMarked(view)) { - if (!view->hasArrayBuffer()) + if (!view->hasArrayBuffer() && !isUnaccounted) m_unmaterializedArrayBufferBytes -= view->byteLengthRaw(); if (previous) previous->setNextUnmaterializedView(next); else m_unmaterializedArrayBufferViews = next; - } else + } else { + if (isUnaccounted) + m_unmaterializedArrayBufferBytes += view->byteLengthRaw(); previous = view; + } view = next; } m_oldUnmaterializedArrayBufferViews = m_unmaterializedArrayBufferViews; + m_accountedUnmaterializedArrayBufferViews = m_unmaterializedArrayBufferViews; #endif } diff --git a/Source/JavaScriptCore/heap/Heap.h b/Source/JavaScriptCore/heap/Heap.h index 96dc70b6ac0c7..fcae814f870d8 100644 --- a/Source/JavaScriptCore/heap/Heap.h +++ b/Source/JavaScriptCore/heap/Heap.h @@ -587,12 +587,12 @@ class Heap { #if USE(BUN_JSC_ADDITIONS) size_t allocatedArrayBufferSize() const { return m_arrayBufferMemoryAccount->allocatedBytes(); } size_t heldArrayBufferSize() const { return m_arrayBufferMemoryAccount->externalBytes(); } - size_t arrayBufferPayloadSize() const { return heldArrayBufferSize() + m_unmaterializedArrayBufferBytes; } + size_t arrayBufferPayloadSize() const { return heldArrayBufferSize() + unmaterializedArrayBufferSize(); } size_t arrayBufferObjectSize() const { return m_arrayBufferMemoryAccount->objectBytes(); } JS_EXPORT_PRIVATE void addUnmaterializedArrayBufferView(JSArrayBufferView*); - void materializeArrayBufferView(size_t bytes) { m_unmaterializedArrayBufferBytes -= bytes; } + JS_EXPORT_PRIVATE size_t unmaterializedArrayBufferSize() const; + void materializeArrayBufferView(size_t bytes) { m_unmaterializedArrayBufferBytes = unmaterializedArrayBufferSize() - bytes; } JSArrayBufferView** addressOfUnmaterializedArrayBufferViews() { return &m_unmaterializedArrayBufferViews; } - size_t* addressOfUnmaterializedArrayBufferBytes() { return &m_unmaterializedArrayBufferBytes; } void didAllocateArrayBufferMemory(size_t bytes) { m_arrayBufferBytesAllocated += bytes; } void reportArrayBufferMemoryAllocated(size_t, const JSCell* = nullptr); ArrayBufferMemoryAccount& arrayBufferMemoryAccount() { return m_arrayBufferMemoryAccount.get(); } @@ -1024,7 +1024,8 @@ class Heap { Ref m_arrayBufferMemoryAccount { ArrayBufferMemoryAccount::create() }; JSArrayBufferView* m_unmaterializedArrayBufferViews { nullptr }; JSArrayBufferView* m_oldUnmaterializedArrayBufferViews { nullptr }; - size_t m_unmaterializedArrayBufferBytes { 0 }; + mutable JSArrayBufferView* m_accountedUnmaterializedArrayBufferViews { nullptr }; + mutable size_t m_unmaterializedArrayBufferBytes { 0 }; uint64_t m_arrayBufferBytesAllocated { 0 }; uint64_t m_arrayBufferBytesAllocatedAtLastCollection { 0 }; uint64_t m_bytesAllocatedAtLastReportingCollection { 0 }; diff --git a/Source/JavaScriptCore/parser/SourceProvider.cpp b/Source/JavaScriptCore/parser/SourceProvider.cpp index bc5c9c6aa51d3..ddd3e0e3871c8 100644 --- a/Source/JavaScriptCore/parser/SourceProvider.cpp +++ b/Source/JavaScriptCore/parser/SourceProvider.cpp @@ -320,8 +320,12 @@ static unsigned lineEndFor(StringView text, const EncodedLineStarts& lineStarts, LineColumn LineStartTable::lineColumnForOffset(StringView text, unsigned offset) { Locker locker { m_lock }; - auto line = EncodedLineStarts { ensureBuilt(text).bytes }.lineContaining(offset); - return { line.line0Based, offset - line.start }; + // Syntax-selected stack positions bypass the per-instruction expression cache. + // Cache provider-relative coordinates so document offsets remain applied by the caller. + return m_cachedLineColumns.ensure(offset, [&] { + auto line = EncodedLineStarts { ensureBuilt(text).bytes }.lineContaining(offset); + return LineColumn { line.line0Based, offset - line.start }; + }).iterator->value; } LineStartTable::PositionInfo LineStartTable::positionInfoForOffset(StringView text, unsigned offset) @@ -365,4 +369,3 @@ LineColumn BuiltinsSourceProvider::lineColumnInTextForOffset(unsigned offset) } } // namespace JSC - diff --git a/Source/JavaScriptCore/parser/SourceProvider.h b/Source/JavaScriptCore/parser/SourceProvider.h index 423b7514e2f09..bdd7760015ccd 100644 --- a/Source/JavaScriptCore/parser/SourceProvider.h +++ b/Source/JavaScriptCore/parser/SourceProvider.h @@ -43,6 +43,7 @@ WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN #include #include #include +#include #include #include #include @@ -125,6 +126,8 @@ class LineStartTable { mutable Lock m_lock; LineStarts m_lineStarts WTF_GUARDED_BY_LOCK(m_lock); + using LineColumnMap = UncheckedKeyHashMap, WTF::UnsignedWithZeroKeyHashTraits>; + LineColumnMap m_cachedLineColumns WTF_GUARDED_BY_LOCK(m_lock); }; class JS_EXPORT_PRIVATE SourceProvider : public ThreadSafeRefCounted { @@ -505,4 +508,4 @@ class SourceProviderBufferGuard { SourceProvider* m_sourceProvider { nullptr }; }; -} // namespace JSC \ No newline at end of file +} // namespace JSC From 405eb84219f51426c88b41884462f641ee02721a Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 4 Oct 2026 19:25:12 -0700 Subject: [PATCH 2/5] fix: include the existing WTF hash map header --- Source/JavaScriptCore/parser/SourceProvider.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/JavaScriptCore/parser/SourceProvider.h b/Source/JavaScriptCore/parser/SourceProvider.h index bdd7760015ccd..264633da658b3 100644 --- a/Source/JavaScriptCore/parser/SourceProvider.h +++ b/Source/JavaScriptCore/parser/SourceProvider.h @@ -40,10 +40,10 @@ WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN #include #include #include +#include #include #include #include -#include #include #include #include From 863eb85bc0ebd41e19ac3b8d33e177704168e792 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 4 Oct 2026 20:00:15 -0700 Subject: [PATCH 3/5] perf: streamline uninspected typed array collection --- .../stack-position-regressions-cache.js | 10 +++--- Source/JavaScriptCore/heap/Heap.cpp | 33 ++++++++++++------- Source/JavaScriptCore/runtime/ArrayBuffer.cpp | 2 +- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/JSTests/stress/stack-position-regressions-cache.js b/JSTests/stress/stack-position-regressions-cache.js index 0b726ce007362..d9b9fd0375156 100644 --- a/JSTests/stress/stack-position-regressions-cache.js +++ b/JSTests/stress/stack-position-regressions-cache.js @@ -11,10 +11,10 @@ for (const terminator of ["\n", "\r\n", "\u2028", "\u2029"]) { } for (let repeat = 0; repeat < Math.min(testLoopCount, 30); ++repeat) { for (const { create, line, column } of sources) { - const stack = create().stack; - const firstFrame = stack.split("\n").find(frame => /:(\d+):(\d+)\)?$/.test(frame)); - const match = /:(\d+):(\d+)\)?$/.exec(firstFrame); - if (!match || Number(match[1]) !== line || Number(match[2]) !== column) - throw new Error(`Expected ${line}:${column}, got ${stack}`); + const error = create(); + // Anonymous eval frames omit their URL from stack strings, but expose + // the same computed coordinates through JSC's error properties. + if (error.line !== line || error.column !== column) + throw new Error(`Expected ${line}:${column}, got ${error.line}:${error.column}`); } } diff --git a/Source/JavaScriptCore/heap/Heap.cpp b/Source/JavaScriptCore/heap/Heap.cpp index 06d8df4cb2a12..a66df2e81bd45 100644 --- a/Source/JavaScriptCore/heap/Heap.cpp +++ b/Source/JavaScriptCore/heap/Heap.cpp @@ -3215,23 +3215,32 @@ void Heap::sweepArrayBuffers() // Surviving views are old after each sweep. Eden cannot reclaim that suffix. auto* end = collectionScope() == CollectionScope::Full ? nullptr : m_oldUnmaterializedArrayBufferViews; auto* view = m_unmaterializedArrayBufferViews; - bool isUnaccounted = true; + auto removeView = [&](JSArrayBufferView* next) { + if (previous) + previous->setNextUnmaterializedView(next); + else + m_unmaterializedArrayBufferViews = next; + }; + // Materialization first accounts the prefix. Its remaining unaccounted + // views therefore need neither a buffer-mode check nor a dead-byte debit. + while (view != m_accountedUnmaterializedArrayBufferViews) { + ASSERT(!view->hasArrayBuffer()); + auto* next = view->nextUnmaterializedView(); + if (isMarked(view)) { + m_unmaterializedArrayBufferBytes += view->byteLengthRaw(); + previous = view; + } else + removeView(next); + view = next; + } while (view != end) { - if (view == m_accountedUnmaterializedArrayBufferViews) - isUnaccounted = false; auto* next = view->nextUnmaterializedView(); if (view->hasArrayBuffer() || !isMarked(view)) { - if (!view->hasArrayBuffer() && !isUnaccounted) + if (!view->hasArrayBuffer()) m_unmaterializedArrayBufferBytes -= view->byteLengthRaw(); - if (previous) - previous->setNextUnmaterializedView(next); - else - m_unmaterializedArrayBufferViews = next; - } else { - if (isUnaccounted) - m_unmaterializedArrayBufferBytes += view->byteLengthRaw(); + removeView(next); + } else previous = view; - } view = next; } m_oldUnmaterializedArrayBufferViews = m_unmaterializedArrayBufferViews; diff --git a/Source/JavaScriptCore/runtime/ArrayBuffer.cpp b/Source/JavaScriptCore/runtime/ArrayBuffer.cpp index 435636355bbb4..247296c9dae38 100644 --- a/Source/JavaScriptCore/runtime/ArrayBuffer.cpp +++ b/Source/JavaScriptCore/runtime/ArrayBuffer.cpp @@ -722,7 +722,7 @@ void ArrayBuffer::updateExternalMemoryAccounting(size_t bytes) return; if (bytes > m_externalBytes) m_holderAccount->acquire(bytes - m_externalBytes); - else + else if (bytes < m_externalBytes) m_holderAccount->release(m_externalBytes - bytes); m_externalBytes = bytes; } From ccacf3cacb8678d7a3d6790d5d5ea21c0c32432a Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 4 Oct 2026 20:26:06 -0700 Subject: [PATCH 4/5] ci: qualify both fork engine artifacts at exact PR heads --- .github/workflows/openclaw-checks.yml | 27 ++++++++++++++++++++++++++- OPENCLAW.md | 15 ++++++++++----- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/.github/workflows/openclaw-checks.yml b/.github/workflows/openclaw-checks.yml index d651cb1493da7..d0b352b32988b 100644 --- a/.github/workflows/openclaw-checks.yml +++ b/.github/workflows/openclaw-checks.yml @@ -16,7 +16,8 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: - fetch-depth: 16 + ref: ${{ github.event.pull_request.head.sha || github.sha }} + fetch-depth: 0 persist-credentials: false sparse-checkout-cone-mode: false sparse-checkout: | @@ -118,3 +119,27 @@ jobs: ${{ runner.temp }}/stack-results/*.log if-no-files-found: error retention-days: 7 + macos-fork-artifact: + if: github.repository == 'openclaw/WebKit' + runs-on: blacksmith-32vcpu-ubuntu-2404 + timeout-minutes: 150 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + ref: ${{ github.event.pull_request.head.sha || github.sha }} + fetch-depth: 0 + persist-credentials: false + sparse-checkout-cone-mode: false + sparse-checkout: | + /* + !/LayoutTests/ + !/JSTests/* + !/PerformanceTests/ + !/Websites/ + !/ManualTests/ + !/WebDriverTests/ + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 + with: + node-version: '26.3.0' + - name: Build the macOS fork artifact on Linux without publishing + run: python3 .github/openclaw/artifacts.py build --lane bun-webkit-macos-arm64 --output "$RUNNER_TEMP/macos-fork-artifact" diff --git a/OPENCLAW.md b/OPENCLAW.md index 4b0f3e63a655f..62d7f0ed7b405 100644 --- a/OPENCLAW.md +++ b/OPENCLAW.md @@ -54,8 +54,11 @@ Batch 1 is published from `openclaw/batch-1` so concurrently reviewed batch-2 engine changes can land on `openclaw/main` without entering this release. Both branches require the same protected environment and full-SHA/green-job checks. -Pull requests run **OpenClaw engine checks**, a read-only Linux build using the same -lane recipe and Bun qualification gate. It also runs the ArrayBuffer accounting +Pull requests run **OpenClaw engine checks** at the exact PR head, with a native +Linux build using the same lane recipe and Bun qualification gate, plus the +macOS arm64 fork artifact cross-built on a separate Linux runner. Both jobs are +read-only; the macOS lane proves compilation, not native macOS execution. +The native job also runs the ArrayBuffer accounting and confirmed parked-waiter inspection regression with LLInt, DFG, FTL and concurrent GC. This workflow provides the pre-merge check; it cannot publish. @@ -143,7 +146,8 @@ baseline. Engine and Bun headers and libraries must be rebuilt together. ## Unreleased - Cache source-relative stack line and column lookups on demand, including syntax-selected positions. -- Defer FastTypedArray byte summation until inspection, materialization, or collection while retaining exact worker snapshots. +- Defer FastTypedArray byte summation until inspection, materialization, or collection while retaining exact worker snapshots; skip unchanged external-byte atomic updates. +- Build both fork engine artifacts at the exact pull-request head before landing, with native Linux qualification and a Linux-hosted macOS arm64 compilation check. - Keep syntax-selected stack positions separate from exception ranges for calls, constructors, property reads, and async continuations. Preserve the positions across bytecode rewriting, optimization, and cache replay. - Add real byte-based JSC heap allocation sampling with weighted allocating-stack profiles and independent major/minor collection inclusion. @@ -161,8 +165,9 @@ Bun must be rebuilt with its matching stack-reader adapter. It must also preserv The source provider caches only requested line/column conversions under its existing line-table lock. Coordinates remain relative to the provider's text; document -offsets and builtin provider overrides retain their existing behavior. Nothing is -computed at throw time or added to the persistent bytecode-cache format. +offsets and builtin provider overrides retain their existing behavior. The cache +fills only when a reader requests a position, and the persistent bytecode-cache +format is unchanged. Unmaterialized typed-array views remain in the VM-owned weak list. Allocations prepend their views without updating a second byte counter. Statistics and From 64b0148f17cad0a27dd2899c39f9c133d5a98945 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 4 Oct 2026 20:55:13 -0700 Subject: [PATCH 5/5] perf: retain constant-time ArrayBuffer snapshots --- JSTests/stress/array-buffer-accounting.js | 26 ------------ OPENCLAW.md | 8 ---- .../JavaScriptCore/dfg/DFGSpeculativeJIT.cpp | 4 ++ Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp | 2 + Source/JavaScriptCore/heap/Heap.cpp | 41 ++++--------------- Source/JavaScriptCore/heap/Heap.h | 9 ++-- Source/JavaScriptCore/runtime/ArrayBuffer.cpp | 2 +- 7 files changed, 18 insertions(+), 74 deletions(-) diff --git a/JSTests/stress/array-buffer-accounting.js b/JSTests/stress/array-buffer-accounting.js index c5aa645308af1..81563bb56c98e 100644 --- a/JSTests/stress/array-buffer-accounting.js +++ b/JSTests/stress/array-buffer-accounting.js @@ -175,29 +175,3 @@ var modeSharedView = new Uint8Array(modeShared); modeShared.grow(32); equal(modeSharedView.length, 32, "grown shared auto length"); equal(modeSharedView[24], 0, "grown shared indexed bounds"); - -// Read fresh allocations after materializing an old view, and collect a prefix -// that has never been inspected. Neither operation may lose or double its bytes. -var deferredViews = [allocate(37)]; -fullGC(); -var deferredBefore = memoryUsage().arrayBuffers; -for (var i = 0; i < 64; ++i) - deferredViews.push(allocate(17)); -deferredViews[0].buffer; -equal(memoryUsage().arrayBuffers, deferredBefore + 64 * 17, "old materialization with a fresh prefix"); -for (var i = 0; i < 64; ++i) - deferredViews.push(allocate(17)); -edenGC(); -equal(memoryUsage().arrayBuffers, deferredBefore + 128 * 17, "uninspected live prefix after eden"); -deferredViews.push(allocate(0)); -deferredViews[deferredViews.length - 1].buffer; -equal(memoryUsage().arrayBuffers, deferredBefore + 128 * 17, "empty materialization"); -fullGC(); -var uninspectedBefore = memoryUsage().arrayBuffers; -temporary = []; -garbage(); -temporary = null; -fullGC(); -equal(memoryUsage().arrayBuffers, uninspectedBefore, "uninspected dead prefix after full GC"); -deferredViews.push(allocate(19)); -equal(memoryUsage().arrayBuffers, uninspectedBefore + 19, "allocation after prefix reclamation"); diff --git a/OPENCLAW.md b/OPENCLAW.md index 62d7f0ed7b405..720377913d125 100644 --- a/OPENCLAW.md +++ b/OPENCLAW.md @@ -146,7 +146,6 @@ baseline. Engine and Bun headers and libraries must be rebuilt together. ## Unreleased - Cache source-relative stack line and column lookups on demand, including syntax-selected positions. -- Defer FastTypedArray byte summation until inspection, materialization, or collection while retaining exact worker snapshots; skip unchanged external-byte atomic updates. - Build both fork engine artifacts at the exact pull-request head before landing, with native Linux qualification and a Linux-hosted macOS arm64 compilation check. - Keep syntax-selected stack positions separate from exception ranges for calls, constructors, property reads, and async continuations. Preserve the positions across bytecode rewriting, optimization, and cache replay. @@ -168,10 +167,3 @@ line-table lock. Coordinates remain relative to the provider's text; document offsets and builtin provider overrides retain their existing behavior. The cache fills only when a reader requests a position, and the persistent bytecode-cache format is unchanged. - -Unmaterialized typed-array views remain in the VM-owned weak list. Allocations -prepend their views without updating a second byte counter. Statistics and -materialization sum only the prefix added since the last observation, and collection -accounts surviving new views while pruning dead ones. All reporting still runs on -the owning VM thread, including busy and parked workers; it never returns a deferred -estimate. Materialized backing stores retain their cross-thread atomic accounts. diff --git a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp index 0d3534fb32b1e..195f2e4a30541 100644 --- a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp +++ b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp @@ -11679,6 +11679,10 @@ void SpeculativeJIT::emitNewTypedArrayWithSizeInRegister(Node* node, TypedArrayT or64(TrustedImm64(JSArrayBufferView::fastModeBits()), scratchGPR); store64(scratchGPR, Address(resultGPR, JSArrayBufferView::offsetOfModeAndNext())); storePtr(resultGPR, Address(scratchGPR2)); + move(sizeGPR, scratchGPR); + lshiftPtr(TrustedImm32(logElementSize(typedArrayType)), scratchGPR); + move(TrustedImmPtr(vm().heap.addressOfUnmaterializedArrayBufferBytes()), scratchGPR2); + add64(scratchGPR, Address(scratchGPR2)); #else store8(TrustedImm32(FastTypedArray), Address(resultGPR, JSArrayBufferView::offsetOfMode())); #endif diff --git a/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp b/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp index a17aff55abfe7..6f40c3f064f3f 100644 --- a/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp +++ b/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp @@ -11359,10 +11359,12 @@ IGNORE_CLANG_WARNINGS_END #endif #if USE(BUN_JSC_ADDITIONS) auto listAddress = m_out.absolute(vm().heap.addressOfUnmaterializedArrayBufferViews()); + auto bytesAddress = m_out.absolute(vm().heap.addressOfUnmaterializedArrayBufferBytes()); auto modeAndNext = m_out.bitOr(m_out.loadPtr(listAddress), m_out.constInt64(JSArrayBufferView::fastModeBits())); // The packed store initializes mode too, so mode loads must alias it. m_out.storePtr(modeAndNext, m_out.address(m_heaps.JSArrayBufferView_mode, fastResultValue, JSArrayBufferView::offsetOfModeAndNext())); m_out.storePtr(fastResultValue, listAddress); + m_out.storePtr(m_out.add(m_out.loadPtr(bytesAddress), byteSizeWithoutAdjustment), bytesAddress); #else m_out.store32As8(m_out.constInt32(FastTypedArray), fastResultValue, m_heaps.JSArrayBufferView_mode); #endif diff --git a/Source/JavaScriptCore/heap/Heap.cpp b/Source/JavaScriptCore/heap/Heap.cpp index a66df2e81bd45..f39cd6d5cd522 100644 --- a/Source/JavaScriptCore/heap/Heap.cpp +++ b/Source/JavaScriptCore/heap/Heap.cpp @@ -1100,7 +1100,7 @@ size_t Heap::objectCount() size_t Heap::arrayBufferSize() { #if USE(BUN_JSC_ADDITIONS) - return allocatedArrayBufferSize() + unmaterializedArrayBufferSize(); + return allocatedArrayBufferSize() + m_unmaterializedArrayBufferBytes; #else return m_arrayBuffers.size(); #endif @@ -1112,18 +1112,7 @@ void Heap::addUnmaterializedArrayBufferView(JSArrayBufferView* view) ASSERT(!view->hasArrayBuffer()); view->setNextUnmaterializedView(m_unmaterializedArrayBufferViews); m_unmaterializedArrayBufferViews = view; -} - -size_t Heap::unmaterializedArrayBufferSize() const -{ - // Inspections run on the owning VM thread. Only allocations since the last - // inspection, materialization or collection need to be added to its total. - for (auto* view = m_unmaterializedArrayBufferViews; view != m_accountedUnmaterializedArrayBufferViews; view = view->nextUnmaterializedView()) { - ASSERT(!view->hasArrayBuffer()); - m_unmaterializedArrayBufferBytes += view->byteLengthRaw(); - } - m_accountedUnmaterializedArrayBufferViews = m_unmaterializedArrayBufferViews; - return m_unmaterializedArrayBufferBytes; + m_unmaterializedArrayBufferBytes += view->byteLengthRaw(); } void Heap::didAllocateArrayBufferAuxiliaryMemory(Subspace* subspace, size_t bytes) @@ -1148,7 +1137,7 @@ size_t Heap::externalMemorySizeForReporting() { return m_nativeExternalMemoryAfterLastCollection + (m_nonArrayBufferBytesAllocated - m_nonArrayBufferBytesAllocatedAtLastCollection) - + arrayBufferPayloadSize() + arrayBufferObjectSize(); + + heldArrayBufferSize() + m_unmaterializedArrayBufferBytes + arrayBufferObjectSize(); } size_t Heap::jsHeapSizeForReporting() @@ -3215,36 +3204,20 @@ void Heap::sweepArrayBuffers() // Surviving views are old after each sweep. Eden cannot reclaim that suffix. auto* end = collectionScope() == CollectionScope::Full ? nullptr : m_oldUnmaterializedArrayBufferViews; auto* view = m_unmaterializedArrayBufferViews; - auto removeView = [&](JSArrayBufferView* next) { - if (previous) - previous->setNextUnmaterializedView(next); - else - m_unmaterializedArrayBufferViews = next; - }; - // Materialization first accounts the prefix. Its remaining unaccounted - // views therefore need neither a buffer-mode check nor a dead-byte debit. - while (view != m_accountedUnmaterializedArrayBufferViews) { - ASSERT(!view->hasArrayBuffer()); - auto* next = view->nextUnmaterializedView(); - if (isMarked(view)) { - m_unmaterializedArrayBufferBytes += view->byteLengthRaw(); - previous = view; - } else - removeView(next); - view = next; - } while (view != end) { auto* next = view->nextUnmaterializedView(); if (view->hasArrayBuffer() || !isMarked(view)) { if (!view->hasArrayBuffer()) m_unmaterializedArrayBufferBytes -= view->byteLengthRaw(); - removeView(next); + if (previous) + previous->setNextUnmaterializedView(next); + else + m_unmaterializedArrayBufferViews = next; } else previous = view; view = next; } m_oldUnmaterializedArrayBufferViews = m_unmaterializedArrayBufferViews; - m_accountedUnmaterializedArrayBufferViews = m_unmaterializedArrayBufferViews; #endif } diff --git a/Source/JavaScriptCore/heap/Heap.h b/Source/JavaScriptCore/heap/Heap.h index fcae814f870d8..96dc70b6ac0c7 100644 --- a/Source/JavaScriptCore/heap/Heap.h +++ b/Source/JavaScriptCore/heap/Heap.h @@ -587,12 +587,12 @@ class Heap { #if USE(BUN_JSC_ADDITIONS) size_t allocatedArrayBufferSize() const { return m_arrayBufferMemoryAccount->allocatedBytes(); } size_t heldArrayBufferSize() const { return m_arrayBufferMemoryAccount->externalBytes(); } - size_t arrayBufferPayloadSize() const { return heldArrayBufferSize() + unmaterializedArrayBufferSize(); } + size_t arrayBufferPayloadSize() const { return heldArrayBufferSize() + m_unmaterializedArrayBufferBytes; } size_t arrayBufferObjectSize() const { return m_arrayBufferMemoryAccount->objectBytes(); } JS_EXPORT_PRIVATE void addUnmaterializedArrayBufferView(JSArrayBufferView*); - JS_EXPORT_PRIVATE size_t unmaterializedArrayBufferSize() const; - void materializeArrayBufferView(size_t bytes) { m_unmaterializedArrayBufferBytes = unmaterializedArrayBufferSize() - bytes; } + void materializeArrayBufferView(size_t bytes) { m_unmaterializedArrayBufferBytes -= bytes; } JSArrayBufferView** addressOfUnmaterializedArrayBufferViews() { return &m_unmaterializedArrayBufferViews; } + size_t* addressOfUnmaterializedArrayBufferBytes() { return &m_unmaterializedArrayBufferBytes; } void didAllocateArrayBufferMemory(size_t bytes) { m_arrayBufferBytesAllocated += bytes; } void reportArrayBufferMemoryAllocated(size_t, const JSCell* = nullptr); ArrayBufferMemoryAccount& arrayBufferMemoryAccount() { return m_arrayBufferMemoryAccount.get(); } @@ -1024,8 +1024,7 @@ class Heap { Ref m_arrayBufferMemoryAccount { ArrayBufferMemoryAccount::create() }; JSArrayBufferView* m_unmaterializedArrayBufferViews { nullptr }; JSArrayBufferView* m_oldUnmaterializedArrayBufferViews { nullptr }; - mutable JSArrayBufferView* m_accountedUnmaterializedArrayBufferViews { nullptr }; - mutable size_t m_unmaterializedArrayBufferBytes { 0 }; + size_t m_unmaterializedArrayBufferBytes { 0 }; uint64_t m_arrayBufferBytesAllocated { 0 }; uint64_t m_arrayBufferBytesAllocatedAtLastCollection { 0 }; uint64_t m_bytesAllocatedAtLastReportingCollection { 0 }; diff --git a/Source/JavaScriptCore/runtime/ArrayBuffer.cpp b/Source/JavaScriptCore/runtime/ArrayBuffer.cpp index 247296c9dae38..435636355bbb4 100644 --- a/Source/JavaScriptCore/runtime/ArrayBuffer.cpp +++ b/Source/JavaScriptCore/runtime/ArrayBuffer.cpp @@ -722,7 +722,7 @@ void ArrayBuffer::updateExternalMemoryAccounting(size_t bytes) return; if (bytes > m_externalBytes) m_holderAccount->acquire(bytes - m_externalBytes); - else if (bytes < m_externalBytes) + else m_holderAccount->release(m_externalBytes - bytes); m_externalBytes = bytes; }