prometheus/model/labels
Oleg Zaytsev 9699598952
Improve Labels.Compare performance w/stringlabels
I was bored on a train and I spent some amount of time trying to scratch
some nanoseconds off the Labels.Compare when running with stringlabels.

I would be ashamed to admit the real amount of time I spent on it.

The worst thing is, I can't really explain why this is performing so
much better, and someone should re-run the benchmarks on their machine
to confirm that it's not something related to general relativity because
the train is moving. I also added some extra real-life benchmark cases
with longer labelsets (these aren't the longest we have in production,
but kubernetes labelsets are fairly common in Prometheus so I thought it
would be nice to have them).

My benchmarks show this diff:

goos: darwin
goarch: arm64
pkg: github.com/prometheus/prometheus/model/labels
                                       │     old     │                 new                 │
                                       │   sec/op    │   sec/op     vs base                │
Labels_Compare/equal                     5.898n ± 0%   5.875n ± 1%   -0.40% (p=0.037 n=10)
Labels_Compare/not_equal                 11.78n ± 2%   11.01n ± 1%   -6.54% (p=0.000 n=10)
Labels_Compare/different_sizes           4.959n ± 1%   4.906n ± 2%   -1.05% (p=0.050 n=10)
Labels_Compare/lots                      21.32n ± 0%   17.54n ± 5%  -17.75% (p=0.000 n=10)
Labels_Compare/real_long_equal           15.06n ± 1%   14.92n ± 0%   -0.93% (p=0.000 n=10)
Labels_Compare/real_long_different_end   25.20n ± 0%   24.43n ± 0%   -3.04% (p=0.000 n=10)
geomean                                  11.86n        11.25n        -5.16%

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
2024-03-17 17:08:06 +01:00
..
labels_common.go labels: optimize String method (#13673) 2024-03-12 11:34:03 +00:00
labels_dedupelabels.go Move from golang.org/x/exp/slices into slices now that we only support Go >= 1.21 2024-02-28 14:54:53 +01:00
labels_stringlabels.go Improve Labels.Compare performance w/stringlabels 2024-03-17 17:08:06 +01:00
labels_test.go Improve Labels.Compare performance w/stringlabels 2024-03-17 17:08:06 +01:00
labels.go Move from golang.org/x/exp/slices into slices now that we only support Go >= 1.21 2024-02-28 14:54:53 +01:00
matcher_test.go feat: dont compile regex matcher if we know its a literal (#12434) 2023-06-07 21:54:30 +01:00
matcher.go
regexp_test.go
regexp.go feat: dont compile regex matcher if we know its a literal (#12434) 2023-06-07 21:54:30 +01:00
sharding_dedupelabels.go labels: update copyright dates 2024-02-26 11:45:25 +00:00
sharding_stringlabels.go Add ShardedPostings() support to TSDB (#10421) 2024-01-29 11:57:27 +00:00
sharding_test.go Add ShardedPostings() support to TSDB (#10421) 2024-01-29 11:57:27 +00:00
sharding.go Add dedupelabels tag to not build regular labels 2024-02-23 13:50:27 +00:00
test_utils.go Labels: Call NewScratchBuilder in test_utils 2024-02-23 13:50:27 +00:00