Repository navigation
Replace quadratic string concatenation in qualified struct type names - #1607
Merged
dmitriplotnikov merged 3 commits intoNov 5, 2026
Merged
Conversation
TristonianJones
previously approved these changes
Nov 3, 2026
- Build qualified message type names with a pre-sized `strings.Builder` in `antlrVisitor.VisitCreateMessage` instead of repeated `+=` string concatenation.
- Assemble qualified struct type names in a single `strings.Builder` pass in `prattParserWorker.extractStructName` instead of `name = "." + sel.FieldName() + name`, and delete intermediate `Select`/`Ident` IDs outermost-to-innermost only after confirming an `ast.IdentKind` root.
- Add `TestParseDeepQualifiedStructName` and `BenchmarkParseLargePathological`.
Benchmarks (`go test -bench='^BenchmarkParseLargePathological/.*/deep_struct_name$' -benchmem`):
goos: linux
goarch: amd64
pkg: cel.dev/cel-go/parser
cpu: Intel(R) Xeon(R) CPU @ 2.20GHz
│ before.txt │ after.txt │
│ sec/op │ sec/op vs base │
ParseLargePathological/antlr/deep_struct_name-8 1508.25m ± 4% 79.91m ± 4% -94.70% (p=0.002 n=6)
ParseLargePathological/pratt/deep_struct_name-8 654.89m ± 111% 39.74m ± 24% -93.93% (p=0.002 n=6)
geomean 993.9m 56.35m -94.33%
│ before.txt │ after.txt │
│ B/op │ B/op vs base │
ParseLargePathological/antlr/deep_struct_name-8 5100.91Mi ± 0% 37.72Mi ± 0% -99.26% (p=0.002 n=6)
ParseLargePathological/pratt/deep_struct_name-8 2537.86Mi ± 0% 12.28Mi ± 0% -99.52% (p=0.002 n=6)
geomean 3.514Gi 21.52Mi -99.40%
│ before.txt │ after.txt │
│ allocs/op │ allocs/op vs base │
ParseLargePathological/antlr/deep_struct_name-8 300.2k ± 2% 200.2k ± 0% -33.32% (p=0.002 n=6)
ParseLargePathological/pratt/deep_struct_name-8 200.0k ± 0% 150.1k ± 0% -24.97% (p=0.002 n=6)
geomean 245.1k 173.3k -29.27%
Collect qualified struct name segments in a pre-allocated slice while deleting intermediate `Select`/`Ident` IDs inline, then reverse and join with `strings.Join` instead of tracking a separate `ids` slice and pre-computing length for `strings.Builder`.
dmitriplotnikov
force-pushed
the
parser-struct-name-builder
branch
from
November 5, 2026 21:25
b2cf5e0 to
ba2f0a9
Compare
TristonianJones
approved these changes
Nov 5, 2026
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.
strings.BuilderinantlrVisitor.VisitCreateMessageinstead of repeated+=string concatenation.strings.Builderpass inprattParserWorker.extractStructNameinstead ofname = "." + sel.FieldName() + name, and delete intermediateSelect/IdentIDs inline.TestParseDeepQualifiedStructNameandBenchmarkParseLargePathological.Benchmarks (
go test -bench='^BenchmarkParseLargePathological/.*/deep_struct_name$' -benchmem)goos: linux·goarch: amd64·pkg: cel.dev/cel-go/parser·cpu: AMD EPYC 7B13before.txt(sec/op)after.txt(sec/op)ParseLargePathological/antlr/deep_struct_name-64ParseLargePathological/pratt/deep_struct_name-64before.txt(B/op)after.txt(B/op)ParseLargePathological/antlr/deep_struct_name-64ParseLargePathological/pratt/deep_struct_name-64before.txt(allocs/op)after.txt(allocs/op)ParseLargePathological/antlr/deep_struct_name-64ParseLargePathological/pratt/deep_struct_name-64