Skip to content

perf: inline getArg(source) in generatedPositionFor#73

Merged
7rulnik merged 1 commit into
mainfrom
perf/inline-getarg-gpf-source
May 10, 2026
Merged

perf: inline getArg(source) in generatedPositionFor#73
7rulnik merged 1 commit into
mainfrom
perf/inline-getarg-gpf-source

Conversation

@7rulnik
Copy link
Copy Markdown
Owner

@7rulnik 7rulnik commented May 10, 2026

Summary

Follow-up to #72: generatedPositionFor still reads source through util.getArg even after #72 inlined line / column. Same megamorphic-call-site exposure — and same magnitude of payoff once inlined.

source can legitimately be null (sources arrays accept null entries), so the typeof !== 'number' validation from #72 doesn't fit. Behavior is preserved by deferring the "is a required argument" throw to the slow path: _findSourceIndex runs first; only if its lookup fails AND the key is absent from aArgs does the throw fire. Defined values (the hot path) take a single property access and never see the in check.

Results (bench-diff vs main, SOLO)

babel.min.js.map (2 runs, full-phase third run for sanity)

phase run 1 run 2
Generated Positions speed +23.3% +21.8%
Generated Positions init +0.3% +0.1%

Full-phase run also showed Trace speed (random) at +11.9% as a positive halo (V8 IC sharing across opf/gpf paths).

vscode.map (5 runs)

run Δ
1 +2.1%
2 −4.6%
3 +1.0%
4 +0.6%
5 +13.4%

Median +1.0%, mean +2.5% — within noise. (An earlier draft that did the 'source' in aArgs check on the hot path regressed vscode by a reproducible 5–16%; moving the check to the slow path eliminated that.)

Behavior

Throw on missing source key is preserved: gpf({line: 1, column: 0}) still throws Error('"source" is a required argument.'). The throw is just delayed until after the slab lookup, which is fine because the lookup is cheap and the throw is fatal anyway.

Test plan

  • yarn test — 205/205 non-TODO tests pass
  • Two babel runs reproduce the +22% win on Generated Positions speed
  • Five vscode runs confirm no regression after moving the in check to the slow path

@7rulnik 7rulnik force-pushed the perf/inline-getarg-gpf-source branch from b301161 to 6e7c982 Compare May 10, 2026 23:31
@7rulnik 7rulnik merged commit be7165b into main May 10, 2026
3 checks passed
@7rulnik 7rulnik deleted the perf/inline-getarg-gpf-source branch May 10, 2026 23:33
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