Skip to content

model: fingerprint up to 64 labels without allocating - #1050

Closed
ultrotter wants to merge 1 commit into
prometheus:mainfrom
ultrotter:labelset-fingerprint-buf64
Closed

ultrotter wants to merge 1 commit into
prometheus:mainfrom
ultrotter:labelset-fingerprint-buf64

Conversation

@ultrotter

Copy link
Copy Markdown
Contributor

This is based on #1049 and uses a new in-between function to optimize the 64-labels case without impacting the smaller ones. Sending separately as it might not be necessarily worth it, but up to us if we merge it or not.

Add a 64-name stack buffer for sets of 33 to 64 labels, kept in a
separate non-inlined frame so that the common path up to 32 labels does
not reserve it. The collect, sort and hash loop moves into a shared
hashLabelNames that takes the buffer, or the heap slice for larger sets,
as an argument.

Frame locals: labelsToFingerprint 616 bytes plus hashLabelNames 336,
against 872 before, and labelsToFingerprintLarge 1088 only on its path.

benchstat n=10, labelset-subset-fingerprint tip vs this, binaries run
interleaved:
                                    before        after
    MetricToFingerprintTriple      181.2n ± 4%   178.1n ± 1%   -1.71% (p=0.003)
    MetricToFingerprintTwenty      1.115µ ± 7%   1.138µ ± 2%        ~ (p=0.110)
    MetricToFingerprintThirtyThree 2.228µ ± 1%   2.019µ ±11%   -9.40% (p=0.009)  1 -> 0 allocs
    MetricToFingerprintSixtyFour   5.484µ ± 2%   4.943µ ± 1%   -9.87% (p=0.000)  1 -> 0 allocs
    LabelSetFingerprintForLabels   95.84n ± 1%   95.10n ± 1%        ~ (p=0.060)

    Signed-off-by: Guido Trotter <guido@hudson-trading.com>

@ultrotter
ultrotter force-pushed the labelset-fingerprint-buf64 branch from 6c8370d to f92c508 Compare November 24, 2026 08:31
Add a 64-name stack buffer for sets of 33 to 64 labels, kept in a
separate non-inlined frame so that the common path up to 32 labels does
not reserve it. The collect, sort and hash loop moves into a shared
hashLabelNames that takes the buffer, or the heap slice for larger sets,
as an argument.

Frame locals: labelsToFingerprint 712 bytes plus hashLabelNames 336,
against 968 before, and labelsToFingerprintLarge 1088 only on its path.

benchstat n=10, labelset-subset-fingerprint tip vs this, binaries run
interleaved:

                                before        after
MetricToFingerprintTriple      173.3n ± 1%   175.7n ± 0%   +1.33% (p=0.001)
MetricToFingerprintTwenty      1.118µ ± 3%   1.118µ ± 1%        ~ (p=0.590)
MetricToFingerprintThirtyThree 2.250µ ± 3%   2.004µ ± 1%  -10.91% (p=0.000)  1 -> 0 allocs
MetricToFingerprintSixtyFour   5.457µ ± 3%   4.913µ ± 2%   -9.96% (p=0.000)  1 -> 0 allocs
LabelSetFingerprintForLabels   97.31n ± 0%   94.53n ± 0%   -2.86% (p=0.000)

Signed-off-by: Guido Trotter <guido@hudson-trading.com>
@ultrotter
ultrotter force-pushed the labelset-fingerprint-buf64 branch from f92c508 to 70fb198 Compare November 24, 2026 08:33
@ultrotter ultrotter closed this Nov 24, 2026
@ultrotter
ultrotter deleted the labelset-fingerprint-buf64 branch November 25, 2026 10:42
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.

1 participant