perf: defer Position alloc in exprSuffix2 to the matching branch#877
Open
He-Pin wants to merge 1 commit into
Open
perf: defer Position alloc in exprSuffix2 to the matching branch#877He-Pin wants to merge 1 commit into
He-Pin wants to merge 1 commit into
Conversation
2 tasks
2 tasks
Motivation:
exprSuffix2 was `Pos.flatMapX { i => CharIn(".[({")... }`, which allocated a
Position on EVERY attempt — including the failing attempt that terminates
`exprSuffix2.rep` after each expression. Most subexpressions have no suffix, so
that trailing failed attempt (one per expression) allocated a Position that was
immediately discarded.
Modification:
- Match the suffix char first; allocate `new Position(fileScope, ctx.index - 1)`
only inside the matching branch. No suffix -> CharIn fails fast, no Position.
Also drops the `.map(_(0))` Char step. Parse output (positions/errors) is
unchanged.
Result:
JMH ParserBenchmark (-f0, same-session): 1.560 -> 1.530 ms/op (+1.9%). Native
parse_time on kube-prometheus: non-regressing, min/p25 ~2% lower (noise-limited
on a loaded machine). Output byte-identical. 517/517 tests pass.
061c6ce to
572d45c
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.
Motivation
exprSuffix2wasPos.flatMapX { i => CharIn(".[({") ... }, which allocated aPositionon every attempt — including the failing attempt that terminatesexprSuffix2.repafter each expression. Most subexpressions have no suffix, so that trailing failed attempt allocates aPositionthat is immediately discarded.Modification
new Position(fileScope, ctx.index - 1)only inside the matching branch. No suffix →CharInfails fast, noPosition. Also drops the intermediate.map(_(0))step. Parse output (positions / error offsets) is unchanged.Result
ParserBenchmark(JVM, over the test suite): 1.560 → 1.530 ms/op (+1.9%, non-overlapping bands).--debug-stats parse_timeon kube-prometheus (interleaved, cooled): neutral-to-slightly-faster (min 89.1 vs 95.9 ms; mean 107.7 vs 110.0 ms — within noise on this loaded run, no regression).Test plan
./mill __.reformat./mill 'sjsonnet.jvm[3.3.7]'.test— 518/518 pass