perf: inline optional getArg in BasicSourceMapConsumer constructor#63
Merged
Conversation
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.
cdb1845 to
d4d2649
Compare
Owner
Author
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.
Summary
Counterpart to #62 — five
util.getArg(sourceMap, X, default)sites inBasicSourceMapConsumer():names(default[]— Sass 3.3 deviation)sourceRoot(defaultnull)sourcesContent(defaultnull)file(defaultnull)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._parseMappingsdominates 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):Tests
yarn test:coveragethresholds (98/97/96) green:lib/source-map-consumer.js: 99.93 / 98.34 / 97.30