Skip to content

PromQL: Speed up parsing of variadic functions#17316

Merged
bwplotka merged 2 commits intoprometheus:mainfrom
bboreham:expect-type
Oct 10, 2025
Merged

PromQL: Speed up parsing of variadic functions#17316
bwplotka merged 2 commits intoprometheus:mainfrom
bboreham:expect-type

Conversation

@bboreham
Copy link
Member

@bboreham bboreham commented Oct 9, 2025

Defer formatting of an error message until we hit an error.

Also add a benchmark case.

goos: darwin
goarch: arm64
pkg: github.com/prometheus/prometheus/promql
cpu: Apple M2
                                                             │    before    │               after                │
                                                             │    sec/op    │   sec/op     vs base               │
Parser/min_over_time(rate(foo{bar="baz"}[2s])[5m:])[4m:3s]-8    2.345µ ± 1%   2.111µ ± 1%  -10.00% (p=0.002 n=6)
Parser/sort_by_label(metric,_"foo",_"bar")-8                   1302.5n ± 3%   908.0n ± 2%  -30.29% (p=0.002 n=6)

                                                             │   before   │               after               │
                                                             │    B/op    │    B/op     vs base               │
Parser/min_over_time(rate(foo{bar="baz"}[2s])[5m:])[4m:3s]-8   976.0 ± 0%   888.0 ± 0%   -9.02% (p=0.002 n=6)
Parser/sort_by_label(metric,_"foo",_"bar")-8                   656.0 ± 0%   512.0 ± 0%  -21.95% (p=0.002 n=6)

                                                             │   before   │               after               │
                                                             │ allocs/op  │ allocs/op   vs base               │
Parser/min_over_time(rate(foo{bar="baz"}[2s])[5m:])[4m:3s]-8   24.00 ± 0%   20.00 ± 0%  -16.67% (p=0.002 n=6)
Parser/sort_by_label(metric,_"foo",_"bar")-8                   18.00 ± 0%   12.00 ± 0%  -33.33% (p=0.002 n=6)

Does this PR introduce a user-facing change?

[PERF] PromQL: Speed up parsing of variadic functions

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
Defer formatting of an error message until we hit an error.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
@bboreham bboreham requested a review from roidelapluie as a code owner October 9, 2025 21:34
Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Classic optimization, love it.

Why there's a linter/AI for it? 🙈

@bwplotka bwplotka merged commit 1c58399 into prometheus:main Oct 10, 2025
28 checks passed
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.

2 participants