Skip to content

perf(runtime): reduce RegExp and constructor allocations - #101

Merged
dirkdev98 merged 2 commits into
mainfrom
perf/benchmark-worktree-20261108
Nov 8, 2026
Merged

dirkdev98 merged 2 commits into
mainfrom
perf/benchmark-worktree-20261108

Conversation

@dirkdev98

@dirkdev98 dirkdev98 commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Ordinary constructors allocate extra slot storage when writing their initial fields, and discarded RegExp matches still allocate result Arrays. Reserve capacity for constructible ordinary functions while preserving every property store, and extend the existing RegExp projection to ignored/null-tested results.

Constructor hints affect allocation capacity only. Setters, callbacks, conditional property presence, returned replacement objects and failed stores retain their behavior. Derived, generator, async and nonconstructible functions receive no hint; class initialization proofs stay separate.

Seven matched AC pairs on 100 unchanged Earley+Boyer calls:

Before 3664 ms (MAD 9), after 2615 ms (MAD 7)
Paired median time reduction: 28.6%
Checksum: 9515600 in Maligator, Node and Bun

Separate three-pair resource probes show median peak RSS of 127.2 to 71.0 MiB for EarleyBoyer. Splay trades 180.3 for 186.5 MiB. Fixed Splay (186 to 183 ms) and am3 (1070 to 1056 ms) show little timing change, so no additional holdout speedup is claimed.

Three matched full V8 pairs for constructor capacity, all checks passing:

V8 v7 score Before After
Total 6715 7183
Richards 5578 6178
DeltaBlue 4714 4800
Crypto 15119 15027
RayTrace 8641 8714
EarleyBoyer 9228 12790
RegExp 832 823
Splay 11258 12281
NavierStokes 14218 14471

Constructor validation: 343 focused compiler tests, ordinary/class-constructor UBSan checks with compiled/interpreted and GC-stress parity, type-check and lint. The native fixture also verifies a callback preventing extensions before strict property stores. Broad acceptance remains with current-head CI.

Closed-world code that discards regexp.exec() results or only checks them against null still builds match Arrays. Extend the existing projection contract to zero captures and use one runtime call that preserves the captured callee, coercion, lastIndex, legacy match state and generic fallback.

The fused call uses the existing matcher and fits the compiler's expansion budget without raising its limits. A native counter verifies successful result elision; backend parity covers mutable and locked primordials, GC stress, subclass and altered-prototype receivers, coercion order, throwing lastIndex, captured getters and custom exec methods. The final combined change advances runtime wire to 86 and compiler artifacts to 373, invalidating earlier internal cache formats.

Seven matched AC pairs on ten unchanged RegExpRun calls reduce 1059 ms (MAD 4) to 1019 ms (MAD 4), a 3.4% paired reduction. Node and Bun agree on the final legacy-state checksum. Three full V8 pairs retain all internal checks and sub-scores below; control variation prevents an overall speedup claim.

V8 v7 score Before After
Total 6925 6951
Richards 5715 5662
DeltaBlue 4655 4675
Crypto 15187 15191
RayTrace 8844 8632
EarleyBoyer 9476 9679
RegExp 850 869
Splay 12696 12436
NavierStokes 14561 14456

Validation: 326 focused compiler checks, targeted UBSan backend and GC-stress parity, existing capture-span and locked-regex checks, regex-disabled native checks, type-check and lint pass. Saved benchmark baselines remain unchanged. The preceding numeric-loop and short-string slices are already merged in PR #100.

Final-source controls retain the original serial-compute improvement: seven matched AC pairs, 902.9 ms (MAD 0.5) to 189.9 ms (MAD 0.045), a 79.0% paired reduction against the original 6edfcf1 compiler. All checksums match; this does not resolve the broader JavaScript v1/v2 controls.

The refreshed three-engine V8 comparison uses three interleaved measured runs plus warmups, all internal checks passing and ready/AC probes around every sample. Porffor a081ebd71177 and Bun 1.4.4 were verified as current upstream. These adaptive cross-engine scores are indicative.

V8 v7 score Maligator Porffor Bun
Total 7154 7034 88192
Richards 6178 5235 58905
DeltaBlue 4688 5170 103739
Crypto 15396 9810 103351
RayTrace 8706 8402 238794
EarleyBoyer 12830 14102 135468
RegExp 816 1131 32067
Splay 11637 16681 100707
NavierStokes 14456 11009 55650

The final diagnostic profile has good capture quality, 2123 CPU samples, no dropped records and complete attribution. It points to remaining RegExp work; its timings and allocation traffic are not performance acceptance evidence.

- Retain captured callee authority while projecting unused or null-tested matches.
- Preserve conversion, lastIndex and legacy effects in one runtime call with generic fallback.
- Validate focused compiler and native checks, GC stress and disabled builds; seven matched fixed-work pairs improve 3.4%.
- Preserve property publication and setters while avoiding extra slot allocations.

- Validate constructor eligibility across Core and wire metadata; advance cache identities.

- Cover constructor parity and GC boundaries; measure fixed EarleyBoyer and V8 holdouts.
@dirkdev98 dirkdev98 changed the title perf(runtime): elide unobserved RegExp result arrays perf(runtime): reduce RegExp and constructor allocations Nov 8, 2026
@dirkdev98
dirkdev98 merged commit fc1ec4d into main Nov 8, 2026
12 checks passed
@dirkdev98
dirkdev98 deleted the perf/benchmark-worktree-20261108 branch November 8, 2026 20:46
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