Skip to content

expfmt: check duplicate label names without a map per label - #1052

Open
ZeXi0308 wants to merge 1 commit into
prometheus:mainfrom
ZeXi0308:expfmt-label-check-linear
Open

ZeXi0308 wants to merge 1 commit into
prometheus:mainfrom
ZeXi0308:expfmt-label-check-linear

Conversation

@ZeXi0308

Copy link
Copy Markdown

startLabelName builds a new map of all the labels read so far at each label of a sample, so a sample with n labels costs n maps and n(n+1)/2 inserts. This compares the new label name with the labels read so far and allocates nothing.

BenchmarkTextParseManyLabels (added here), Go 1.27.0 on darwin/arm64 (Apple M5), medians of six runs:

labels on the sample main this PR
1 0.53 µs, 824 B, 25 allocs 0.50 µs, 824 B, 25 allocs
16 6.9 µs, 8,848 B, 162 allocs 2.9 µs, 3,344 B, 134 allocs
40 36.5 µs, 68,368 B, 476 allocs 7.6 µs, 7,760 B, 304 allocs

The new error case has a duplicate that is neither the first label nor next to its duplicate.

#887 makes the same change to the check; this adds the test case and the benchmark.

Fixes #1051

startLabelName built a new map of all the labels read so far at each
label of a sample, so a sample with n labels cost n maps and n(n+1)/2
inserts. Compare the new label name with the labels read so far
instead.

Fixes prometheus#1051

Signed-off-by: Zachary_WX <184957876+ZeXi0308@users.noreply.github.com>
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.

expfmt: TextParser cost grows quadratically with the number of labels on a sample

1 participant