Build the QSA wrapper argument list in one allocation - #187
Open
jdalton wants to merge 1 commit into
Open
Conversation
jdalton
force-pushed
the
perf/wrapper-arguments
branch
2 times, most recently
from
September 5, 2026 02:48
7738820 to
8f7780c
Compare
jdalton
force-pushed
the
perf/wrapper-arguments
branch
from
September 6, 2026 02:30
8f7780c to
8e9fa4a
Compare
The wrappers install() puts on the DOM prototypes forward their arguments to parseQSArgs as [].slice.call(arguments).concat(resolver), which allocates twice for a call that carries at most three arguments. argsWith() sizes the list by arity in a single allocation, unrolled to eight and falling through to the general form beyond that.
Measured in isolation, building the list drops from ~113ns to ~9ns, and with the apply included from ~119ns to ~14ns.
End to end in Chromium, three rounds with the order swapped, an installed querySelector('#root') against a 200-element document:
before 175ns 174ns 168ns (wrapper 98ns, 97ns, 94ns) after 95ns 92ns 90ns (wrapper 19ns, 17ns, 17ns)
That is 1.85x on a cheap query, where fixed overhead is most of the call and the wrapper was 56% of it. On an expensive one it disappears into the query: the same change against a 200-match 'p.x' is ~1% of 11.7us and not separable from run-to-run noise.
References:
- MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments — the arguments object these wrappers forward
jdalton
force-pushed
the
perf/wrapper-arguments
branch
from
September 6, 2026 11:40
8e9fa4a to
2c9a16e
Compare
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.
Tooling update
Rebased onto merged #212 as one commit. Sources and tests use
.mts, Node tests use Vitest, and the published JavaScript paths stay unchanged. The original engine changes are preserved.Local lint, formatting, Node and packed-package checks pass. All 41 WPT pages pass against both generated builds.
Change
The wrappers
install()puts on the DOM prototypes forward their arguments as a slice concatenated with the resolver, which allocates twice for a call carrying at most three arguments. Sizing the list by arity in one allocation is 1.85x on an installed querySelector for a cheap selector, and invisible on an expensive one.Detail, and how it was checked
The wrappers
install()puts on the DOM prototypes forward their arguments to parseQSArgs as [].slice.call(arguments).concat(resolver), which allocates twice for a call that carries at most three arguments.argsWith()sizes the list by arity in a single allocation, unrolled to eight and falling through to the general form beyond that.Measured in isolation, building the list drops from ~113ns to ~9ns, and with the apply included from ~119ns to ~14ns.
End to end in Chromium, three rounds with the order swapped, an installed querySelector(
#root) against a 200-element document:That is 1.85x on a cheap query, where fixed overhead is most of the call and the wrapper was 56% of it. On an expensive one it disappears into the query: the same change against a 200-match
p.xis ~1% of 11.7us and not separable from run-to-run noise.Extracted from #167 as a standalone change: one file, applies to master on its own, and checked against the benchmark fixture to confirm every selector still agrees with the native engine.
References: the spec, the browser source, and what each part was reasoned from
This patch applies to master on its own. The sixteen in this series were checked by cherry-picking them onto master one after another, in this order and in reverse, and all sixteen land without a conflict.
arguments— the arguments object these wrappers forward.