Skip to content

perf: inline optional getArg in BasicSourceMapConsumer constructor#63

Merged
7rulnik merged 1 commit into
mainfrom
perf/consumer-ctor-inline-with-tests
May 10, 2026
Merged

perf: inline optional getArg in BasicSourceMapConsumer constructor#63
7rulnik merged 1 commit into
mainfrom
perf/consumer-ctor-inline-with-tests

Conversation

@7rulnik
Copy link
Copy Markdown
Owner

@7rulnik 7rulnik commented May 10, 2026

Summary

Counterpart to #62 — five util.getArg(sourceMap, X, default) sites in BasicSourceMapConsumer():

  • names (default [] — Sass 3.3 deviation)
  • sourceRoot (default null)
  • sourcesContent (default null)
  • file (default null)

Replaced with sourceMap.X != null ? sourceMap.X : default. Same pattern as #59 / #60 / #62.

Bench

Honest result: this one is a wash. Originally measured +1.1%; re-benched after rebase onto main (with #64/#65/#66 landed): mean −0.49% across 12 init-bench rows, range −3.8% to +3.1% — within fixture variance.

Unlike #62 (where the SourceMapGenerator ctor inline saw +8.7% on addMapping, likely from V8 hidden-class effects helping the downstream per-mapping hot loop), the consumer ctor isn't followed by a hot loop in the same bench cycle. _parseMappings dominates init cost, so saving four function calls in the preamble is unmeasurable.

Keeping the change anyway for codebase consistency — without it, a future reader of #62 would have to wonder why one constructor was inlined and the other left alone.

SOLO=1 PHASES=init scripts/bench-diff.sh main trace (two-process, ops/sec via benchmark.js, after rebase):

Fixture JSON cand JSON base JSON Δ Object cand Object base Object Δ
amp.js.map 521 ±0.39% 527 ±0.44% -1.1% 617 ±0.43% 641 ±0.29% -3.7%
babel.min.js.map 78.03 78.52 -0.6% 91.38 89.74 +1.8%
issue-41.js.map 112 ±1.41% 112 ±1.59% 0.0% 127 ±0.92% 127 ±0.85% 0.0%
preact.js.map 9,340 ±0.23% 9,460 ±0.40% -1.3% 18,566 ±0.51% 19,292 ±0.30% -3.8%
react.js.map 5,605 ±0.59% 5,691 ±0.34% -1.5% 6,727 ±0.27% 6,680 ±0.42% +0.7%
vscode.map 5.40 ±5.72% 5.24 ±6.00% +3.1% 7.15 ±5.58% 7.11 ±9.18% +0.6%
mean -0.49%

Tests

  • All 205 existing tests pass.
  • yarn test:coverage thresholds (98/97/96) green:
    • lib/source-map-consumer.js: 99.93 / 98.34 / 97.30
    • all files: 98.35 / 97.21 / 96.75
  • No new tests needed — the existing fixture set already exercises both branches of each default ternary, so coverage holds on its own.

Four sites — names, sourceRoot, sourcesContent, file — all optional with
documented defaults. Same pattern as #59 / #60 / #62.

Init bench shows mostly noise — mean +1.09% across 12 rows, range
-3.7% to +7.1%. Unlike the SourceMapGenerator ctor change in #62 (which
saw +8.7% on the addMapping bench, attributable to V8 hidden-class
effects helping the downstream hot path), the consumer ctor isn't
followed by a per-mapping hot loop in the same cycle — _parseMappings
dominates init cost, so saving four function calls in the preamble is
unmeasurable.

Keeping it anyway for consistency with the codebase pattern and to
prevent #62's followup readers from wondering why one ctor was inlined
and the other was left alone.

scripts/bench-diff.sh main trace (SOLO=1 PHASES=init):

  amp.js.map        JSON -2.5% / Object -0.8%
  babel.min.js.map  JSON +2.2% / Object +3.7%
  issue-41.js.map   JSON -3.7% / Object  0.0%
  preact.js.map     JSON +4.3% / Object +3.8%
  react.js.map      JSON -1.6% / Object +1.5%
  vscode.map        JSON -1.0% / Object +7.1%
  mean              +1.09%

Coverage holds: branch 97.16 / 98.75 (just above 97 / 98 thresholds).
No new tests needed — existing fixtures already exercise the default
branches.
@7rulnik 7rulnik force-pushed the perf/consumer-ctor-inline-with-tests branch from cdb1845 to d4d2649 Compare May 10, 2026 21:10
@7rulnik
Copy link
Copy Markdown
Owner Author

7rulnik commented May 10, 2026

Re-benched after rebase onto current main (with #64 / #65 / #66 landed). Result holds: mean −0.49% across 12 init rows (range −3.8% to +3.1%) — wash, within fixture variance. Original conclusion unchanged. Pushed rebased branch to update the diff.

@7rulnik 7rulnik merged commit 1118684 into main May 10, 2026
3 checks passed
@7rulnik 7rulnik deleted the perf/consumer-ctor-inline-with-tests branch May 10, 2026 21:11
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