Repository navigation
perf(runtime): reduce RegExp and constructor allocations - #101
Merged
Merged
Conversation
- 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.
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.
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:
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:
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
RegExpRuncalls 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.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.
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.