Skip to content

perf: close gaps against Porffor and Bun - #98

Merged
dirkdev98 merged 13 commits into
mainfrom
perf/vs-porffor-bun
Nov 8, 2026
Merged

dirkdev98 merged 13 commits into
mainfrom
perf/vs-porffor-bun

Conversation

@dirkdev98

@dirkdev98 dirkdev98 commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Benchmarked our closed-world production builds against Porffor (alpha 22, a081ebd) and Bun 1.4.4 on Porffor's bench/*.js and our bench/javascript*.mjs. This PR collects the fixes from that run; each commit stands on its own.

  • Small ArrayBuffers keep stores up to 256 bytes in their own cell, so allocation skips calloc and the sweep skips the finalizer and free. 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 of arrayBuffers, like V8's on-heap typed arrays.
  • Arrays keep up to 14 elements in their cell (was 8), and cells up to 256 bytes are cleared with inline stores instead of a memset call.
  • Inherited accessor rows admit a second receiver layout with the same holder and accessor. A site alternating between a class and its subclass used to refill on every miss and decline after four refills.
  • Native function slots (promise resolving functions and the like) live in the function's cell.
  • Numeric sorts with exactly (a, b) => a - b or b - a take 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.assign copies plain data sources onto plain targets through spread's merge under locked primordials; __proto__ keys, accessors and non-default targets keep the generic loop.
  • Inlined map creates its result through ArrayCreate(len), which is what ArraySpeciesCreate does for a default species, and ArrayCreate(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 interned constructor key instead of hashing it per call.
  • TODO.md records what's left: startup primordials, regress' UTF-16 prefilter, and an array literal region miss.
interleaved A/B, one machine, indicative      before    after
Porffor allocate_small                           155       82
4M new Uint8Array(16)                            190      111
4M ten-element array literals                    105       47
javascript-v2 dynamicObjects, 40 rounds         1660      960
1M await new Promise((r) => r(i))                118      108
javascript-v1 collections, 20 rounds            1200     1020
5M Array.prototype.slice.call(arguments)         1198       26
1M Object.assign({}, record, { e })               496       92
10M twelve-element maps                          1245     1118
10M new Array(16) fills                          1248     1187

tests/native/forwarded-sort-callback.test.ts fails locally on macOS with origin/main's runtime and compiler too (sort nomination counters); Linux CI passes it.

- 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).
@dirkdev98
dirkdev98 merged commit 62bc536 into main Nov 8, 2026
12 checks passed
@dirkdev98
dirkdev98 deleted the perf/vs-porffor-bun branch November 8, 2026 00:16
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.

1 participant