Skip to content

QueryResult: use stdlib for envelope decoding - #2110

Merged
bwplotka merged 2 commits into
prometheus:mainfrom
liggitt:query-result
Sep 10, 2026
Merged

QueryResult: use stdlib for envelope decoding#2110
bwplotka merged 2 commits into
prometheus:mainfrom
liggitt:query-result

Conversation

@liggitt

@liggitt liggitt commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

cc @bwplotka

part of #2105

  1. Adds a benchmark for QueryResult decoding
  2. Switches to stdlib for the outer envelope decoding only (benchmarks show the json-iterator-optimized secondary decodings are still faster than plain stdlib, will address those in follow-ups)

Benchmark results of switching the envelope decode to stdlib:

For scalar query results (tiny)

  • cpu is worse on go 1.26 and 1.27, but still nanoseconds,
  • allocs and bytes are worse on go 1.26, better on go 1.27

For vector and matrix query results (large)

  • cpu is worse on go 1.26, better or neutral on go 1.27
  • allocs and bytes are better on go 1.26 and go 1.27
goos: darwin
goarch: arm64
pkg: github.com/prometheus/client_golang/api/prometheus/v1
cpu: Apple M4 Pro
                                │ main-jsoniter │              go1.26.6              │              go1.27.1              │
                                │    sec/op     │   sec/op     vs base               │   sec/op     vs base               │
QueryResult/scalar-14               473.4n ± 4%   731.7n ± 2%  +54.58% (p=0.002 n=6)   611.6n ± 1%  +29.22% (p=0.002 n=6)
QueryResult/vector-14               74.66µ ± 9%   86.01µ ± 1%  +15.20% (p=0.002 n=6)   63.21µ ± 1%  -15.33% (p=0.002 n=6)
QueryResult/matrix-float-14         19.59µ ± 7%   26.84µ ± 2%  +37.02% (p=0.002 n=6)   19.69µ ± 1%        ~ (p=0.589 n=6)
QueryResult/matrix-histogram-14     168.8µ ± 3%   268.5µ ± 1%  +59.11% (p=0.002 n=6)   166.3µ ± 2%        ~ (p=0.132 n=6)
geomean                             18.49µ        25.95µ       +40.37%                 18.86µ        +2.02%

                                │ main-jsoniter │              go1.26.6               │              go1.27.1               │
                                │     B/op      │     B/op      vs base               │     B/op      vs base               │
QueryResult/scalar-14                544.0 ± 0%     704.0 ± 0%  +29.41% (p=0.002 n=6)     184.0 ± 0%  -66.18% (p=0.002 n=6)
QueryResult/vector-14              38.04Ki ± 0%   37.88Ki ± 0%   -0.43% (p=0.002 n=6)   24.54Ki ± 0%  -35.48% (p=0.002 n=6)
QueryResult/matrix-float-14        21.33Ki ± 0%   21.24Ki ± 0%   -0.41% (p=0.002 n=6)   17.86Ki ± 0%  -16.28% (p=0.002 n=6)
QueryResult/matrix-histogram-14    133.2Ki ± 0%   131.5Ki ± 0%   -1.23% (p=0.002 n=6)   128.5Ki ± 0%   -3.51% (p=0.002 n=6)
geomean                            15.48Ki        16.42Ki        +6.11%                 10.03Ki       -35.20%

                                │ main-jsoniter │             go1.26.6              │              go1.27.1              │
                                │   allocs/op   │  allocs/op   vs base              │  allocs/op   vs base               │
QueryResult/scalar-14                16.00 ± 0%    17.00 ± 0%  +6.25% (p=0.002 n=6)    10.00 ± 0%  -37.50% (p=0.002 n=6)
QueryResult/vector-14                747.0 ± 0%    689.0 ± 0%  -7.76% (p=0.002 n=6)    670.0 ± 0%  -10.31% (p=0.002 n=6)
QueryResult/matrix-float-14          497.0 ± 0%    459.0 ± 0%  -7.65% (p=0.002 n=6)    410.0 ± 0%  -17.51% (p=0.002 n=6)
QueryResult/matrix-histogram-14     4.567k ± 0%   4.229k ± 0%  -7.40% (p=0.002 n=6)   4.180k ± 0%   -8.47% (p=0.002 n=6)
geomean                              405.8         388.3       -4.32%                  327.3       -19.34%

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

Signed-off-by: Jordan Liggitt <liggitt@google.com>
                                │ 1-query-main.txt │        2-query-envelope.txt        │
                                │      sec/op      │   sec/op     vs base               │
QueryResult/scalar-14                  473.4n ± 4%   731.7n ± 2%  +54.58% (p=0.002 n=6)
QueryResult/vector-14                  74.66µ ± 9%   86.01µ ± 1%  +15.20% (p=0.002 n=6)
QueryResult/matrix-float-14            19.59µ ± 7%   26.84µ ± 2%  +37.02% (p=0.002 n=6)
QueryResult/matrix-histogram-14        168.8µ ± 3%   268.5µ ± 1%  +59.11% (p=0.002 n=6)
geomean                                18.49µ        25.95µ       +40.37%

                                │ 1-query-main.txt │        2-query-envelope.txt         │
                                │       B/op       │     B/op      vs base               │
QueryResult/scalar-14                   544.0 ± 0%     704.0 ± 0%  +29.41% (p=0.002 n=6)
QueryResult/vector-14                 38.04Ki ± 0%   37.88Ki ± 0%   -0.43% (p=0.002 n=6)
QueryResult/matrix-float-14           21.33Ki ± 0%   21.24Ki ± 0%   -0.41% (p=0.002 n=6)
QueryResult/matrix-histogram-14       133.2Ki ± 0%   131.5Ki ± 0%   -1.23% (p=0.002 n=6)
geomean                               15.48Ki        16.42Ki        +6.11%

                                │ 1-query-main.txt │       2-query-envelope.txt        │
                                │    allocs/op     │  allocs/op   vs base              │
QueryResult/scalar-14                   16.00 ± 0%    17.00 ± 0%  +6.25% (p=0.002 n=6)
QueryResult/vector-14                   747.0 ± 0%    689.0 ± 0%  -7.76% (p=0.002 n=6)
QueryResult/matrix-float-14             497.0 ± 0%    459.0 ± 0%  -7.65% (p=0.002 n=6)
QueryResult/matrix-histogram-14        4.567k ± 0%   4.229k ± 0%  -7.40% (p=0.002 n=6)
geomean                                 405.8         388.3       -4.32%

Signed-off-by: Jordan Liggitt <liggitt@google.com>
@liggitt

liggitt commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

rebased

@bwplotka
bwplotka merged commit 959db2a into prometheus:main Sep 10, 2026
15 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.

3 participants