Repository navigation
perf: close gaps against Porffor and Bun - #98
Merged
Merged
Conversation
- Fixed, non-shared, non-sensitive stores up to 256 bytes live in the buffer's own heap cell. Allocation skips calloc, and the minor sweep reclaims them with the cell instead of finalizing and freeing them. - ArrayBuffers no longer finalize from birth; a native store, pin, lease or expando storage marks the cell finalizable, as objects already do. - Pins, store leases, structured-clone transfer and sensitive marking move an inline store to a native allocation first, so C addresses and scrubbing keep their contracts. FFI now pins before reading addresses. - 4M `new ArrayBuffer(128)`: 185 -> 111 ms; 4M `new Uint8Array(16)`: 190 -> 111 ms; Porffor's allocate_small: 155 -> 90 ms (indicative). - Small stores count as heap memory rather than `arrayBuffers`, like V8's on-heap typed arrays; the memory-usage test now uses larger stores.
- Array literals and reserved arrays of 9 to 14 elements now use the cell's inline slots instead of a separate raw vector that the sweep has to free. The 4-bit inline capacity field already allowed 14. - 4M ten-element literals: 105 -> 47 ms (Bun 37, Node 29), indicative. javascript-v1, javascript-v2 and Porffor's linked_list are unchanged.
- Cells in the 144 to 256 byte classes were zeroed through a libc memset call per allocation. Async frames, inline ArrayBuffer stores and arrays with 9 to 14 inline elements land in those classes. - 4M `new ArrayBuffer(128)`: 87.6 -> 81.9 ms; the javascript-v2 async phase about 0.6% faster (indicative). __text grows by 1.2 KiB.
- A getter or setter row now admits a second receiver layout (shape and first prototype) that reaches the same holder's accessor. The second chain joins the row's dependencies, so a change on either chain clears it. - Sites alternating between base-class and subclass instances used to refill the row on every miss and declined after four refills, falling back to generic lookups. - javascript-v2 dynamicObjects, 40 rounds: ~1660 -> ~960 ms (Node 1132, Bun 688), indicative. The getter and setter fixtures now change only the second chain under a warmed site.
- clone-take and utf8-string-storage call retain_store and new_uninitialized with the heap and sensitivity arguments. - clone-take's shared-allocation case uses a store above the inline limit, since a small fixed store lives in its cell and a move copies it.
…for and Bun - Findings from benchmarking closed-world builds against Porffor and Bun, with the measurements that locate each cost.
- Native closures with up to 16 internal slots, such as promise resolving functions and Promise.all element functions, store them after the length/name metadata instead of in a RAW vector the sweep has to free. - Native functions now finalize only when they own a RAW slot vector or object storage, like script functions. - 1M `await new Promise((resolve) => resolve(i))`: ~118 -> ~108 ms (indicative, 3 interleaved pairs); other async micro cases unchanged.
- A numeric sort kernel whose leaf only returns the difference of its two Number parameters now takes a stable LSD radix order for 128 or more elements. Bytes every key shares are skipped; a NaN key keeps the merge. - Without NaN, such a comparator is a consistent total preorder in which only equal Numbers tie (0 and -0 share one key), so the stable radix order is exactly the merge's order. - javascript-v1 collections phase, 20 rounds: ~1200 -> ~1020 ms (indicative); the sort itself was 37% of the phase. - The numeric sort fixture covers 300-element ascending, descending and toSorted orders with ±0 and ±Infinity ties.
…ject - `Array.prototype.slice.call(arguments[, k])` and `[].slice.call(arguments[, k])` in a function whose other `arguments` uses are static now lower to the rest-array operation while primordials are locked. A sloppy function qualifies only when no mapped formal is ever written. - Mutable primordials, shadowed `Array`, arrows, optional chains and element stores keep the real arguments object. - 5M `Array.prototype.slice.call(arguments)` calls: 1198 -> 26 ms (Bun and Node 93), indicative. - Found while testing: entry files compile strict even as plain CommonJS scripts, so AOT fixtures cannot hold sloppy functions; the classification unit test covers the written-formal guard instead.
…pread
- With locked primordials, [[Set]] into an extensible ordinary target whose
prototype is %Object.prototype% and whose own fields are default-attribute
data defines exactly what spread defines, except through the inherited
`__proto__` setter.
- Sources whose properties are all string-keyed data in their shape, and
that have no `__proto__` key, now take spread's shape-cached merge; any
other source or target keeps the generic Get/Set loop.
- 1M `Object.assign({}, record, { e })`: 496 -> 92 ms (Bun 52, Node 27),
indicative.
- New scenarios cover ordered plain sources, a nonenumerable target field
and objects inheriting from the target.
- The slice-copy plan is now separate from the static, guarded and lazy classification and applies only while primordials are locked. - With mutable primordials, a function that reads `arguments.length` and copies through `slice.call(arguments, k)` materializes lazily again on the copy path, and its reads stay guarded, since a patched slice may write to the object.
- Array species checks for inlined map, filter and flatMap, and RegExp species lookups, hashed "constructor" on every call; they now read the hot key. - About 3% of a 12-element map loop's samples, indicative.
- The inlined map creates its result through ArrayCreate(len), which is what ArraySpeciesCreate does for a default species, instead of an empty array that grows per element and receives its length afterwards. - ArrayCreate(len) reserves dense capacity at birth up to 65536 elements, inside the cell when it fits, so `new Array(n)` fills skip regrowth too. - 10M maps of 12 and 16 elements: 1245 -> 1118 and 1550 -> 1454 ms; `new Array(16)` fills 1248 -> 1187 ms (indicative, interleaved pairs).
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.
Benchmarked our closed-world production builds against Porffor (alpha 22,
a081ebd) and Bun 1.4.4 on Porffor'sbench/*.jsand ourbench/javascript*.mjs. This PR collects the fixes from that run; each commit stands on its own.callocand the sweep skips the finalizer andfree. Pins, store leases, structured-clone transfer and sensitive marking move the store out first, and the FFI now pins before it reads an address. Small stores count as heap memory instead ofarrayBuffers, like V8's on-heap typed arrays.memsetcall.(a, b) => a - borb - atake a stable radix order from 128 elements; NaN keys keep the merge.Array.prototype.slice.call(arguments[, k])and[].slice.call(...)build the copy from the frame under locked primordials, without the arguments object. A sloppy function qualifies only when no mapped formal is written. With mutable primordials, the existing lazy materialization and guarded reads stay.Object.assigncopies plain data sources onto plain targets through spread's merge under locked primordials;__proto__keys, accessors and non-default targets keep the generic loop.mapcreates its result throughArrayCreate(len), which is whatArraySpeciesCreatedoes for a default species, andArrayCreate(len)reserves its elements up to 65536 at birth. The result used to grow from 4 slots and get its length at the end. Species checks also read the internedconstructorkey instead of hashing it per call.TODO.mdrecords what's left: startup primordials, regress' UTF-16 prefilter, and an array literal region miss.tests/native/forwarded-sort-callback.test.tsfails locally on macOS with origin/main's runtime and compiler too (sort nomination counters); Linux CI passes it.