Repository navigation
openmetrics 2.0: avoid composite field allocations - #19747
Conversation
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Negative histogram values and IgnoreNativeHistograms behavior require correction.
Review effort: Lite
Findings: None
What changed in this PR
This PR optimizes OpenMetrics 2.0 parsing to reduce allocations and enforce canonical field ordering.
Changes:
- Replaces map-based composite parsing with reusable byte offsets and slices.
- Optimizes native histogram span and bucket parsing.
- Adds field-order validation and updates parser tests.
| File | Summary |
|---|---|
model/textparse/openmetrics2parse.go |
Parser optimization, field-order validation, and histogram handling. |
model/textparse/openmetrics2parse_test.go |
Updated fixtures and ordering-validation tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
56be4c7 to
0ac26e3
Compare
0ac26e3 to
7cd5149
Compare
|
Nice ! |
7cd5149 to
73e5b9a
Compare
bwplotka
left a comment
There was a problem hiding this comment.
Thanks! I wonder if we shouldn't expand our lex instead of AI/hand typing.
Replace per-line kvMap and intermediate string/slice allocations during OpenMetrics 2.0 composite value parsing with byte-offset parsing and stack-allocated compositeFields. Signed-off-by: David Ashpole <[email protected]>
Signed-off-by: David Ashpole <[email protected]>
73e5b9a to
473e5e3
Compare
|
Thanks, did you rerun benchmark on how it compares to new lex implementation? |
|
Yep, updated the PR description with the refreshed benchmarks comparing main, the previous byte-offsets approach, and golex. Comparing golex against byte-offsets, CPU time is within noise / slightly faster on histograms (-3.24% on |
Which issue(s) does the PR fix:
Part of #19745 (item 12 / PR 3).
This PR eliminates per-line
kvMap(map[string]string) and intermediate string/slice allocations during OpenMetrics 2.0 composite value parsing:golexcomposite field lexing (sComposite,sCompValue, &compositeFields): Expandsopenmetrics2lex.lto lex composite delimiters (tCompOpen,tCompClose), field keys (tCompCount..tCompQuantile), commas (tComma), and values (tValue), replacingkvMap(map[string]string) andsplitCompositeFields([]string) with a fixed-size stack-allocatedcompositeFieldsstruct ([numCompFields][]byte+seen uint16bitmask).[]byteparsing for spans and buckets (parseSpans,bucketsHaveFloat,parseIntBuckets,parseFloatBuckets): Replacesstrings.Splitand intermediate string conversions withbytes.SplitSeq,bytes.Cut,yoloString, and pre-sized destination slices viabytes.Count(inner, []byte{','}) + 1.p.extraLabels&&p.ts): Reusesp.extraLabelscapacity across composite series innameAndExtraLabelsFromOffsets()and passes&p.tsinstead of taking the address of a local copy inbuildClassicHistogramPending()andbuildSummaryPending().Benchmarks (
benchstat)Release notes for end users (ALL commits must be considered).
Reviewers should verify clarity and quality.