Skip to content

tsdb.PostingsForMatchers: Optimize inverse matching#14144

Merged
bboreham merged 7 commits intoprometheus:mainfrom
aknuds1:arve/inverse-postings-for-matcher
Nov 19, 2024
Merged

tsdb.PostingsForMatchers: Optimize inverse matching#14144
bboreham merged 7 commits intoprometheus:mainfrom
aknuds1:arve/inverse-postings-for-matcher

Conversation

@aknuds1
Copy link
Copy Markdown
Contributor

@aknuds1 aknuds1 commented May 25, 2024

Simple follow-up to #13620. Just modify tsdb.PostingsForMatchers to use the optimized tsdb.IndexReader.PostingsForLabelMatching method also for inverse matching.

The performance is much improved for a subset of the cases; there are up to ~60% CPU gains and ~12.5% reduction in memory usage. Please consult benchmark statistics below.

Removing TestReader_InversePostingsForMatcherHonorsContextCancel since inversePostingsForMatcher only passes ctx to IndexReader implementations now.

Benchmark results

PostingsForMatchers benchmark stats
goos: linux
goarch: amd64
pkg: github.com/prometheus/prometheus/tsdb
cpu: Intel(R) Xeon(R) Platinum 8358 CPU @ 2.60GHz
                                                                     │ head-postings-main.txt │ head-postings-inverse-postings-for-matchers.txt │
                                                                     │         sec/op         │          sec/op           vs base               │
Querier/Head/PostingsForMatchers/n="1"-8                                         458.0n ±  1%               454.5n ±  3%        ~ (p=0.119 n=6)
Querier/Head/PostingsForMatchers/n="X"-8                                         455.2n ±  0%               449.6n ±  0%   -1.23% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",j="foo"-8                                 723.6n ±  0%               711.5n ±  0%   -1.67% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="X",j="foo"-8                                 511.0n ±  0%               511.2n ±  0%        ~ (p=0.584 n=6)
Querier/Head/PostingsForMatchers/j="foo",n="1"-8                                 723.8n ±  0%               712.4n ±  0%   -1.57% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",j!="foo"-8                                702.8n ±  0%               690.0n ±  0%   -1.83% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i!="2"-8                                  717.8n ±  0%               702.6n ±  0%   -2.11% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="X",j!="foo"-8                                489.4n ±  0%               488.2n ±  0%        ~ (p=0.132 n=6)
Querier/Head/PostingsForMatchers/i=~"1[0-9]",j=~"foo|bar"-8                      1.409µ ±  1%               1.411µ ±  1%        ~ (p=0.604 n=6)
Querier/Head/PostingsForMatchers/j=~"foo|bar"-8                                  802.8n ±  0%               796.1n ±  0%   -0.83% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/j=~"XXX|YYY"-8                                  655.1n ±  0%               658.4n ±  0%   +0.50% (p=0.009 n=6)
Querier/Head/PostingsForMatchers/j=~"X.+"-8                                      605.6n ±  0%               604.3n ±  0%   -0.20% (p=0.041 n=6)
Querier/Head/PostingsForMatchers/i=~"(1|2|3|4|5|6|20|55)"-8                      1.144µ ±  1%               1.119µ ±  0%   -2.23% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/i!~"(1|2|3|4|5|6|20|55)"-8                      1.266µ ±  2%               1.245µ ±  1%   -1.62% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/i=~"X|Y|Z"-8                                    740.2n ±  1%               739.0n ±  0%        ~ (p=0.240 n=6)
Querier/Head/PostingsForMatchers/i!~"X|Y|Z"-8                                    848.2n ±  1%               845.5n ±  1%        ~ (p=0.223 n=6)
Querier/Head/PostingsForMatchers/i=~".*"-8                                       416.0n ±  0%               413.1n ±  0%   -0.71% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/i=~"1.*"-8                                      9.378m ±  6%               7.934m ±  6%  -15.39% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/i=~".*1"-8                                      6.716m ±  1%               6.187m ±  9%   -7.88% (p=0.015 n=6)
Querier/Head/PostingsForMatchers/i=~".+"-8                                       27.34m ±  4%               26.46m ±  6%        ~ (p=0.093 n=6)
Querier/Head/PostingsForMatchers/i=~".+",j=~"X.+"-8                              27.22m ±  3%               25.73m ±  6%   -5.46% (p=0.026 n=6)
Querier/Head/PostingsForMatchers/i=~""-8                                         28.30m ±  4%               11.67m ± 15%  -58.75% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/i!=""-8                                         28.47m ±  2%               11.48m ±  2%  -59.68% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i=~".*",j="foo"-8                         778.2n ±  0%               764.6n ±  1%   -1.75% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="X",i=~".*",j="foo"-8                         557.9n ±  0%               559.0n ±  0%        ~ (p=0.310 n=6)
Querier/Head/PostingsForMatchers/n="1",i=~".*",i!="2",j="foo"-8                  1.034µ ±  0%               1.031µ ±  0%        ~ (p=0.229 n=6)
Querier/Head/PostingsForMatchers/n="1",i!=""-8                                   28.03m ±  2%               11.36m ±  8%  -59.48% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i!="",j="foo"-8                           28.34m ±  3%               11.64m ±  2%  -58.91% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i!="",j=~"X.+"-8                          28.57m ±  2%               11.39m ±  4%  -60.11% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i!="",j=~"XXX|YYY"-8                      28.45m ±  1%               11.19m ±  3%  -60.68% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i=~"X|Y|Z",j="foo"-8                      1.033µ ±  0%               1.041µ ±  0%   +0.82% (p=0.004 n=6)
Querier/Head/PostingsForMatchers/n="1",i!~"X|Y|Z",j="foo"-8                      1.218µ ±  0%               1.221µ ±  0%        ~ (p=0.128 n=6)
Querier/Head/PostingsForMatchers/n="1",i=~".+",j="foo"-8                         27.66m ±  4%               26.18m ±  5%   -5.33% (p=0.009 n=6)
Querier/Head/PostingsForMatchers/n="1",i=~"1.+",j="foo"-8                        9.340m ±  3%               7.358m ± 14%  -21.22% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i=~".*1.*",j="foo"-8                      23.75m ±  2%               21.91m ±  6%   -7.73% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i=~".+",i!="2",j="foo"-8                  27.64m ±  2%               25.85m ±  4%   -6.47% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i=~".+",i!~"2.*",j="foo"-8                36.84m ±  6%               34.57m ±  6%   -6.15% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i=~".+",i!~".*2.*",j="foo"-8              50.36m ±  3%               48.14m ±  6%   -4.41% (p=0.041 n=6)
Querier/Head/PostingsForMatchers/n="X",i=~".+",i!~".*2.*",j="foo"-8              648.4n ±  0%               653.9n ±  0%   +0.85% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1"-8                                        35.12µ ±  1%               34.69µ ±  0%   -1.22% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="X"-8                                        595.4n ±  4%               626.1n ±  2%   +5.14% (p=0.009 n=6)
Querier/Block/PostingsForMatchers/n="1",j="foo"-8                                387.9µ ±  2%               384.8µ ±  2%        ~ (p=0.699 n=6)
Querier/Block/PostingsForMatchers/n="X",j="foo"-8                                607.2n ±  1%               623.6n ±  1%   +2.69% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/j="foo",n="1"-8                                384.8µ ±  1%               384.8µ ±  2%        ~ (p=1.000 n=6)
Querier/Block/PostingsForMatchers/n="1",j!="foo"-8                               385.0µ ±  1%               385.9µ ±  2%        ~ (p=0.699 n=6)
Querier/Block/PostingsForMatchers/n="1",i!="2"-8                                 35.57µ ±  0%               35.63µ ±  0%   +0.16% (p=0.017 n=6)
Querier/Block/PostingsForMatchers/n="X",j!="foo"-8                               568.8n ±  2%               591.8n ±  2%   +4.05% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/i=~"1[0-9]",j=~"foo|bar"-8                     6.005µ ±  0%               5.963µ ±  1%        ~ (p=0.058 n=6)
Querier/Block/PostingsForMatchers/j=~"foo|bar"-8                                 966.3µ ±  3%               951.5µ ±  5%        ~ (p=0.699 n=6)
Querier/Block/PostingsForMatchers/j=~"XXX|YYY"-8                                 552.1n ±  2%               570.9n ±  0%   +3.40% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/j=~"X.+"-8                                     578.8n ±  0%               584.9n ±  0%   +1.05% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/i=~"(1|2|3|4|5|6|20|55)"-8                     4.220µ ±  0%               4.186µ ±  1%   -0.79% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/i!~"(1|2|3|4|5|6|20|55)"-8                     956.9µ ± 17%               961.0µ ±  4%        ~ (p=0.818 n=6)
Querier/Block/PostingsForMatchers/i=~"X|Y|Z"-8                                   686.4n ±  2%               693.8n ±  2%        ~ (p=0.418 n=6)
Querier/Block/PostingsForMatchers/i!~"X|Y|Z"-8                                   979.8µ ± 10%               927.2µ ± 25%        ~ (p=0.180 n=6)
Querier/Block/PostingsForMatchers/i=~".*"-8                                      980.2µ ±  7%               959.1µ ±  4%        ~ (p=0.093 n=6)
Querier/Block/PostingsForMatchers/i=~"1.*"-8                                     3.798m ±  1%               3.795m ±  1%        ~ (p=0.937 n=6)
Querier/Block/PostingsForMatchers/i=~".*1"-8                                     2.514m ±  1%               2.537m ±  1%   +0.91% (p=0.009 n=6)
Querier/Block/PostingsForMatchers/i=~".+"-8                                      17.66m ±  2%               17.69m ±  4%        ~ (p=0.589 n=6)
Querier/Block/PostingsForMatchers/i=~".+",j=~"X.+"-8                             17.67m ±  2%               17.87m ±  1%        ~ (p=0.132 n=6)
Querier/Block/PostingsForMatchers/i=~""-8                                        20.89m ±  2%               16.61m ±  1%  -20.46% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/i!=""-8                                        19.13m ±  2%               14.81m ±  1%  -22.59% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i=~".*",j="foo"-8                        384.9µ ±  1%               386.1µ ±  2%        ~ (p=0.485 n=6)
Querier/Block/PostingsForMatchers/n="X",i=~".*",j="foo"-8                        640.7n ±  1%               661.5n ±  1%   +3.24% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i=~".*",i!="2",j="foo"-8                 386.7µ ±  1%               386.2µ ±  1%        ~ (p=0.485 n=6)
Querier/Block/PostingsForMatchers/n="1",i!=""-8                                  19.14m ±  2%               14.92m ±  1%  -22.04% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i!="",j="foo"-8                          19.97m ±  0%               15.67m ±  1%  -21.53% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i!="",j=~"X.+"-8                         19.22m ±  1%               14.81m ±  2%  -22.95% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i!="",j=~"XXX|YYY"-8                     19.30m ±  1%               14.95m ±  2%  -22.51% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i=~"X|Y|Z",j="foo"-8                     35.13µ ±  0%               35.18µ ±  0%        ~ (p=0.132 n=6)
Querier/Block/PostingsForMatchers/n="1",i!~"X|Y|Z",j="foo"-8                     385.5µ ±  3%               385.9µ ±  1%        ~ (p=0.699 n=6)
Querier/Block/PostingsForMatchers/n="1",i=~".+",j="foo"-8                        18.47m ±  2%               18.71m ±  2%        ~ (p=0.310 n=6)
Querier/Block/PostingsForMatchers/n="1",i=~"1.+",j="foo"-8                       4.555m ±  2%               4.601m ±  3%        ~ (p=0.699 n=6)
Querier/Block/PostingsForMatchers/n="1",i=~".*1.*",j="foo"-8                     11.20m ±  1%               11.11m ±  1%        ~ (p=0.093 n=6)
Querier/Block/PostingsForMatchers/n="1",i=~".+",i!="2",j="foo"-8                 18.54m ±  1%               18.70m ±  1%        ~ (p=0.093 n=6)
Querier/Block/PostingsForMatchers/n="1",i=~".+",i!~"2.*",j="foo"-8               22.38m ±  2%               22.81m ±  2%   +1.95% (p=0.004 n=6)
Querier/Block/PostingsForMatchers/n="1",i=~".+",i!~".*2.*",j="foo"-8             29.12m ±  2%               29.55m ±  1%   +1.47% (p=0.041 n=6)
Querier/Block/PostingsForMatchers/n="X",i=~".+",i!~".*2.*",j="foo"-8             863.0n ±  1%               862.3n ±  3%        ~ (p=0.855 n=6)
geomean                                                                          130.5µ                     118.1µ         -9.52%

                                                                     │ head-postings-main.txt │ head-postings-inverse-postings-for-matchers.txt │
                                                                     │          B/op          │          B/op           vs base                 │
Querier/Head/PostingsForMatchers/n="1"-8                                           64.00 ± 0%               64.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="X"-8                                           48.00 ± 0%               48.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",j="foo"-8                                   176.0 ± 0%               176.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="X",j="foo"-8                                   48.00 ± 0%               48.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/j="foo",n="1"-8                                   176.0 ± 0%               176.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",j!="foo"-8                                  176.0 ± 0%               176.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i!="2"-8                                    176.0 ± 0%               176.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="X",j!="foo"-8                                  48.00 ± 0%               48.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~"1[0-9]",j=~"foo|bar"-8                        512.0 ± 0%               512.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/j=~"foo|bar"-8                                    352.0 ± 0%               352.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/j=~"XXX|YYY"-8                                    128.0 ± 0%               128.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/j=~"X.+"-8                                        80.00 ± 0%               80.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~"(1|2|3|4|5|6|20|55)"-8                        416.0 ± 0%               416.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i!~"(1|2|3|4|5|6|20|55)"-8                        480.0 ± 0%               480.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~"X|Y|Z"-8                                      176.0 ± 0%               176.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i!~"X|Y|Z"-8                                      240.0 ± 0%               240.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~".*"-8                                         64.00 ± 0%               64.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~"1.*"-8                                      2.722Mi ± 0%             2.722Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~".*1"-8                                      1.531Mi ± 0%             1.531Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~".+"-8                                       12.22Mi ± 0%             12.22Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~".+",j=~"X.+"-8                              12.22Mi ± 0%             12.22Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~""-8                                         12.22Mi ± 0%             10.69Mi ± 0%  -12.53% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/i!=""-8                                         12.22Mi ± 0%             10.69Mi ± 0%  -12.53% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i=~".*",j="foo"-8                           176.0 ± 0%               176.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="X",i=~".*",j="foo"-8                           48.00 ± 0%               48.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i=~".*",i!="2",j="foo"-8                    288.0 ± 0%               288.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i!=""-8                                   12.22Mi ± 0%             10.69Mi ± 0%  -12.53% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i!="",j="foo"-8                           12.22Mi ± 0%             10.69Mi ± 0%  -12.53% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i!="",j=~"X.+"-8                          12.22Mi ± 0%             10.69Mi ± 0%  -12.53% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i!="",j=~"XXX|YYY"-8                      12.22Mi ± 0%             10.69Mi ± 0%  -12.53% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i=~"X|Y|Z",j="foo"-8                        240.0 ± 0%               240.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i!~"X|Y|Z",j="foo"-8                        352.0 ± 0%               352.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i=~".+",j="foo"-8                         12.22Mi ± 0%             12.22Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i=~"1.+",j="foo"-8                        2.722Mi ± 0%             2.722Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i=~".*1.*",j="foo"-8                      5.906Mi ± 0%             5.906Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i=~".+",i!="2",j="foo"-8                  12.22Mi ± 0%             12.22Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i=~".+",i!~"2.*",j="foo"-8                14.95Mi ± 0%             14.95Mi ± 0%        ~ (p=1.000 n=6)
Querier/Head/PostingsForMatchers/n="1",i=~".+",i!~".*2.*",j="foo"-8              18.14Mi ± 0%             18.14Mi ± 0%        ~ (p=1.000 n=6)
Querier/Head/PostingsForMatchers/n="X",i=~".+",i!~".*2.*",j="foo"-8                48.00 ± 0%               48.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1"-8                                          80.00 ± 0%               80.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="X"-8                                          64.00 ± 0%               64.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",j="foo"-8                                  208.0 ± 0%               208.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="X",j="foo"-8                                  64.00 ± 0%               64.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/j="foo",n="1"-8                                  208.0 ± 0%               208.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",j!="foo"-8                                 208.0 ± 0%               208.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i!="2"-8                                   208.0 ± 0%               208.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="X",j!="foo"-8                                 64.00 ± 0%               64.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~"1[0-9]",j=~"foo|bar"-8                       352.0 ± 0%               352.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/j=~"foo|bar"-8                                   352.0 ± 0%               352.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/j=~"XXX|YYY"-8                                   96.00 ± 0%               96.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/j=~"X.+"-8                                       48.00 ± 0%               48.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~"(1|2|3|4|5|6|20|55)"-8                       288.0 ± 0%               288.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i!~"(1|2|3|4|5|6|20|55)"-8                       368.0 ± 0%               368.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~"X|Y|Z"-8                                     128.0 ± 0%               128.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i!~"X|Y|Z"-8                                     208.0 ± 0%               208.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~".*"-8                                        80.00 ± 0%               80.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~"1.*"-8                                     1.654Mi ± 0%             1.654Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~".*1"-8                                       48.00 ± 0%               48.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~".+"-8                                      17.67Mi ± 0%             17.67Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~".+",j=~"X.+"-8                             17.67Mi ± 0%             17.67Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~""-8                                        12.22Mi ± 0%             10.69Mi ± 0%  -12.53% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/i!=""-8                                        12.22Mi ± 0%             10.69Mi ± 0%  -12.53% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i=~".*",j="foo"-8                          208.0 ± 0%               208.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="X",i=~".*",j="foo"-8                          64.00 ± 0%               64.00 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i=~".*",i!="2",j="foo"-8                   336.0 ± 0%               336.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i!=""-8                                  12.22Mi ± 0%             10.69Mi ± 0%  -12.53% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i!="",j="foo"-8                          12.22Mi ± 0%             10.69Mi ± 0%  -12.53% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i!="",j=~"X.+"-8                         12.22Mi ± 0%             10.69Mi ± 0%  -12.53% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i!="",j=~"XXX|YYY"-8                     12.22Mi ± 0%             10.69Mi ± 0%  -12.53% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i=~"X|Y|Z",j="foo"-8                       208.0 ± 0%               208.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i!~"X|Y|Z",j="foo"-8                       336.0 ± 0%               336.0 ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i=~".+",j="foo"-8                        17.67Mi ± 0%             17.67Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i=~"1.+",j="foo"-8                       1.654Mi ± 0%             1.654Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i=~".*1.*",j="foo"-8                     6.987Mi ± 0%             6.987Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i=~".+",i!="2",j="foo"-8                 17.67Mi ± 0%             17.67Mi ± 0%        ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i=~".+",i!~"2.*",j="foo"-8               19.33Mi ± 0%             19.33Mi ± 0%        ~ (p=1.000 n=6)
Querier/Block/PostingsForMatchers/n="1",i=~".+",i!~".*2.*",j="foo"-8             24.66Mi ± 0%             24.66Mi ± 0%        ~ (p=0.182 n=6)
Querier/Block/PostingsForMatchers/n="X",i=~".+",i!~".*2.*",j="foo"-8               64.00 ± 0%               64.00 ± 0%        ~ (p=1.000 n=6) ¹
geomean                                                                          11.92Ki                  11.68Ki        -2.04%
¹ all samples are equal

                                                                     │ head-postings-main.txt │ head-postings-inverse-postings-for-matchers.txt │
                                                                     │       allocs/op        │        allocs/op         vs base                │
Querier/Head/PostingsForMatchers/n="1"-8                                           3.000 ± 0%                3.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="X"-8                                           3.000 ± 0%                3.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",j="foo"-8                                   7.000 ± 0%                7.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="X",j="foo"-8                                   3.000 ± 0%                3.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/j="foo",n="1"-8                                   7.000 ± 0%                7.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",j!="foo"-8                                  7.000 ± 0%                7.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i!="2"-8                                    7.000 ± 0%                7.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="X",j!="foo"-8                                  3.000 ± 0%                3.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~"1[0-9]",j=~"foo|bar"-8                        14.00 ± 0%                14.00 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/j=~"foo|bar"-8                                    8.000 ± 0%                8.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/j=~"XXX|YYY"-8                                    6.000 ± 0%                6.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/j=~"X.+"-8                                        4.000 ± 0%                4.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~"(1|2|3|4|5|6|20|55)"-8                        12.00 ± 0%                12.00 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i!~"(1|2|3|4|5|6|20|55)"-8                        15.00 ± 0%                15.00 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~"X|Y|Z"-8                                      7.000 ± 0%                7.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i!~"X|Y|Z"-8                                      10.00 ± 0%                10.00 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~".*"-8                                         3.000 ± 0%                3.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~"1.*"-8                                       11.12k ± 0%               11.12k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~".*1"-8                                        4.000 ± 0%                4.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~".+"-8                                        100.0k ± 0%               100.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~".+",j=~"X.+"-8                               100.0k ± 0%               100.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/i=~""-8                                          100.0k ± 0%               100.0k ± 0%  -0.00% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/i!=""-8                                          100.0k ± 0%               100.0k ± 0%  -0.00% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i=~".*",j="foo"-8                           7.000 ± 0%                7.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="X",i=~".*",j="foo"-8                           3.000 ± 0%                3.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i=~".*",i!="2",j="foo"-8                    11.00 ± 0%                11.00 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i!=""-8                                    100.0k ± 0%               100.0k ± 0%  -0.00% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i!="",j="foo"-8                            100.0k ± 0%               100.0k ± 0%  -0.00% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i!="",j=~"X.+"-8                           100.0k ± 0%               100.0k ± 0%  -0.00% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i!="",j=~"XXX|YYY"-8                       100.0k ± 0%               100.0k ± 0%  -0.00% (p=0.002 n=6)
Querier/Head/PostingsForMatchers/n="1",i=~"X|Y|Z",j="foo"-8                        10.00 ± 0%                10.00 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i!~"X|Y|Z",j="foo"-8                        14.00 ± 0%                14.00 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i=~".+",j="foo"-8                          100.0k ± 0%               100.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i=~"1.+",j="foo"-8                         11.12k ± 0%               11.12k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i=~".*1.*",j="foo"-8                       40.97k ± 0%               40.97k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i=~".+",i!="2",j="foo"-8                   100.0k ± 0%               100.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i=~".+",i!~"2.*",j="foo"-8                 111.2k ± 0%               111.2k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="1",i=~".+",i!~".*2.*",j="foo"-8               141.0k ± 0%               141.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/PostingsForMatchers/n="X",i=~".+",i!~".*2.*",j="foo"-8                3.000 ± 0%                3.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1"-8                                          4.000 ± 0%                4.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="X"-8                                          4.000 ± 0%                4.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",j="foo"-8                                  9.000 ± 0%                9.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="X",j="foo"-8                                  4.000 ± 0%                4.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/j="foo",n="1"-8                                  9.000 ± 0%                9.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",j!="foo"-8                                 9.000 ± 0%                9.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i!="2"-8                                   9.000 ± 0%                9.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="X",j!="foo"-8                                 4.000 ± 0%                4.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~"1[0-9]",j=~"foo|bar"-8                       4.000 ± 0%                4.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/j=~"foo|bar"-8                                   8.000 ± 0%                8.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/j=~"XXX|YYY"-8                                   4.000 ± 0%                4.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/j=~"X.+"-8                                       3.000 ± 0%                3.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~"(1|2|3|4|5|6|20|55)"-8                       4.000 ± 0%                4.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i!~"(1|2|3|4|5|6|20|55)"-8                       8.000 ± 0%                8.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~"X|Y|Z"-8                                     4.000 ± 0%                4.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i!~"X|Y|Z"-8                                     8.000 ± 0%                8.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~".*"-8                                        4.000 ± 0%                4.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~"1.*"-8                                      11.13k ± 0%               11.13k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~".*1"-8                                       3.000 ± 0%                3.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~".+"-8                                       100.0k ± 0%               100.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~".+",j=~"X.+"-8                              100.0k ± 0%               100.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/i=~""-8                                         100.0k ± 0%               100.0k ± 0%  -0.00% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/i!=""-8                                         100.0k ± 0%               100.0k ± 0%  -0.00% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i=~".*",j="foo"-8                          9.000 ± 0%                9.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="X",i=~".*",j="foo"-8                          4.000 ± 0%                4.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i=~".*",i!="2",j="foo"-8                   14.00 ± 0%                14.00 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i!=""-8                                   100.0k ± 0%               100.0k ± 0%  -0.00% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i!="",j="foo"-8                           100.0k ± 0%               100.0k ± 0%  -0.00% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i!="",j=~"X.+"-8                          100.0k ± 0%               100.0k ± 0%  -0.00% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i!="",j=~"XXX|YYY"-8                      100.0k ± 0%               100.0k ± 0%  -0.00% (p=0.002 n=6)
Querier/Block/PostingsForMatchers/n="1",i=~"X|Y|Z",j="foo"-8                       8.000 ± 0%                8.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i!~"X|Y|Z",j="foo"-8                       13.00 ± 0%                13.00 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i=~".+",j="foo"-8                         100.0k ± 0%               100.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i=~"1.+",j="foo"-8                        11.14k ± 0%               11.14k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i=~".*1.*",j="foo"-8                      40.99k ± 0%               40.99k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i=~".+",i!="2",j="foo"-8                  100.0k ± 0%               100.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i=~".+",i!~"2.*",j="foo"-8                111.2k ± 0%               111.2k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="1",i=~".+",i!~".*2.*",j="foo"-8              141.1k ± 0%               141.1k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/PostingsForMatchers/n="X",i=~".+",i!~".*2.*",j="foo"-8               4.000 ± 0%                4.000 ± 0%       ~ (p=1.000 n=6) ¹
geomean                                                                            221.3                     221.3       -0.00%
¹ all samples are equal
labelValuesWithMatchers benchmark stats
goos: linux
goarch: amd64
pkg: github.com/prometheus/prometheus/tsdb
cpu: Intel(R) Xeon(R) Platinum 8358 CPU @ 2.60GHz
                                                                      │ labelvalues-main.txt │ labelvalues-inverse-postings-for-matchers.txt │
                                                                      │        sec/op        │         sec/op           vs base              │
Querier/Head/labelValuesWithMatchers/i_with_i="1"-8                              1.914m ± 2%               1.925m ± 1%       ~ (p=0.310 n=6)
Querier/Head/labelValuesWithMatchers/i_with_n="1"-8                              176.6m ± 8%               178.8m ± 6%       ~ (p=0.699 n=6)
Querier/Head/labelValuesWithMatchers/i_with_n=".+"-8                             119.3m ± 7%               119.8m ± 4%       ~ (p=0.818 n=6)
Querier/Head/labelValuesWithMatchers/i_with_n="1",j!="foo"-8                     200.9m ± 2%               203.9m ± 4%       ~ (p=0.093 n=6)
Querier/Head/labelValuesWithMatchers/i_with_n="1",j=~"X.+"-8                     34.11m ± 4%               35.10m ± 2%  +2.91% (p=0.041 n=6)
Querier/Head/labelValuesWithMatchers/i_with_n="1",j=~"XXX|YYY"-8                 34.53m ± 3%               35.23m ± 3%       ~ (p=0.180 n=6)
Querier/Head/labelValuesWithMatchers/i_with_n="X",j!="foo"-8                     135.1m ± 5%               133.4m ± 4%       ~ (p=0.699 n=6)
Querier/Head/labelValuesWithMatchers/i_with_n="1",i=~".*",j!="foo"-8             200.8m ± 3%               206.0m ± 5%       ~ (p=0.180 n=6)
Querier/Head/labelValuesWithMatchers/i_with_i="1aaa...ddd"-8                     1.898m ± 0%               1.901m ± 1%       ~ (p=0.699 n=6)
Querier/Head/labelValuesWithMatchers/i_with_i=~"1.+"-8                           6.276m ± 6%               6.231m ± 3%       ~ (p=0.310 n=6)
Querier/Head/labelValuesWithMatchers/i_with_i=~"1.+",i=~".+ddd"-8                6.894m ± 8%               6.806m ± 8%       ~ (p=0.394 n=6)
Querier/Head/labelValuesWithMatchers/n_with_j!="foo"-8                           126.7m ± 1%               117.8m ± 1%  -7.01% (p=0.002 n=6)
Querier/Head/labelValuesWithMatchers/n_with_i="1"-8                              7.338µ ± 2%               7.252µ ± 2%       ~ (p=0.093 n=6)
Querier/Head/labelValuesWithMatchers/n_with_i=~"1.+"-8                           22.08m ± 6%               22.23m ± 5%       ~ (p=0.589 n=6)
Querier/Head/labelValuesWithMatchers/none_with_i=~"1"-8                          251.8n ± 2%               253.8n ± 3%       ~ (p=0.195 n=6)
Querier/Block/labelValuesWithMatchers/i_with_i="1"-8                             2.424m ± 1%               2.319m ± 1%  -4.36% (p=0.002 n=6)
Querier/Block/labelValuesWithMatchers/i_with_n="1"-8                             168.8m ± 1%               170.5m ± 1%  +1.01% (p=0.004 n=6)
Querier/Block/labelValuesWithMatchers/i_with_n=".+"-8                            482.8m ± 1%               474.9m ± 1%  -1.64% (p=0.002 n=6)
Querier/Block/labelValuesWithMatchers/i_with_n="1",j!="foo"-8                    177.3m ± 0%               177.8m ± 0%  +0.28% (p=0.015 n=6)
Querier/Block/labelValuesWithMatchers/i_with_n="1",j=~"X.+"-8                    76.86m ± 1%               76.44m ± 2%       ~ (p=0.093 n=6)
Querier/Block/labelValuesWithMatchers/i_with_n="1",j=~"XXX|YYY"-8                76.96m ± 0%               76.41m ± 0%  -0.72% (p=0.002 n=6)
Querier/Block/labelValuesWithMatchers/i_with_n="X",j!="foo"-8                    127.8m ± 1%               127.5m ± 0%       ~ (p=0.240 n=6)
Querier/Block/labelValuesWithMatchers/i_with_n="1",i=~".*",j!="foo"-8            177.5m ± 1%               178.2m ± 3%       ~ (p=0.240 n=6)
Querier/Block/labelValuesWithMatchers/i_with_i="1aaa...ddd"-8                    2.420m ± 1%               2.343m ± 1%  -3.17% (p=0.002 n=6)
Querier/Block/labelValuesWithMatchers/i_with_i=~"1.+"-8                          2.987m ± 1%               2.896m ± 1%  -3.03% (p=0.002 n=6)
Querier/Block/labelValuesWithMatchers/i_with_i=~"1.+",i=~".+ddd"-8               3.207m ± 1%               3.123m ± 1%  -2.63% (p=0.002 n=6)
Querier/Block/labelValuesWithMatchers/n_with_j!="foo"-8                          233.6m ± 0%               232.6m ± 1%       ~ (p=0.240 n=6)
Querier/Block/labelValuesWithMatchers/n_with_i="1"-8                            1012.5µ ± 3%               995.9µ ± 5%       ~ (p=0.310 n=6)
Querier/Block/labelValuesWithMatchers/n_with_i=~"1.+"-8                          5.786m ± 3%               5.724m ± 5%       ~ (p=0.485 n=6)
Querier/Block/labelValuesWithMatchers/none_with_i=~"1"-8                         218.8n ± 4%               218.8n ± 4%       ~ (p=0.699 n=6)
geomean                                                                          10.43m                    10.38m       -0.56%

                                                                      │ labelvalues-main.txt │ labelvalues-inverse-postings-for-matchers.txt │
                                                                      │         B/op         │         B/op           vs base                │
Querier/Head/labelValuesWithMatchers/i_with_i="1"-8                           1.531Mi ± 0%              1.531Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_n="1"-8                           16.14Mi ± 0%              16.14Mi ± 0%       ~ (p=1.000 n=6)
Querier/Head/labelValuesWithMatchers/i_with_n=".+"-8                          16.14Mi ± 0%              16.14Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_n="1",j!="foo"-8                  16.14Mi ± 0%              16.14Mi ± 0%       ~ (p=1.000 n=6)
Querier/Head/labelValuesWithMatchers/i_with_n="1",j=~"X.+"-8                  10.69Mi ± 0%              10.69Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_n="1",j=~"XXX|YYY"-8              10.70Mi ± 0%              10.70Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_n="X",j!="foo"-8                  16.14Mi ± 0%              16.14Mi ± 0%       ~ (p=1.000 n=6)
Querier/Head/labelValuesWithMatchers/i_with_n="1",i=~".*",j!="foo"-8          16.14Mi ± 0%              16.14Mi ± 0%       ~ (p=0.424 n=6)
Querier/Head/labelValuesWithMatchers/i_with_i="1aaa...ddd"-8                  1.531Mi ± 0%              1.531Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_i=~"1.+"-8                        1.531Mi ± 0%              1.531Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_i=~"1.+",i=~".+ddd"-8             1.531Mi ± 0%              1.531Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/n_with_j!="foo"-8                        5.781Ki ± 0%              5.781Ki ± 0%       ~ (p=0.455 n=6)
Querier/Head/labelValuesWithMatchers/n_with_i="1"-8                           4.695Ki ± 0%              4.695Ki ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/n_with_i=~"1.+"-8                        2.728Mi ± 0%              2.728Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/none_with_i=~"1"-8                         0.000 ± 0%                0.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_i="1"-8                          1.531Mi ± 0%              1.531Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_n="1"-8                          17.66Mi ± 0%              17.66Mi ± 0%       ~ (p=1.000 n=6)
Querier/Block/labelValuesWithMatchers/i_with_n=".+"-8                         17.67Mi ± 0%              17.67Mi ± 0%       ~ (p=1.000 n=6)
Querier/Block/labelValuesWithMatchers/i_with_n="1",j!="foo"-8                 17.66Mi ± 0%              17.66Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_n="1",j=~"X.+"-8                 12.22Mi ± 0%              12.22Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_n="1",j=~"XXX|YYY"-8             12.22Mi ± 0%              12.22Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_n="X",j!="foo"-8                 17.66Mi ± 0%              17.66Mi ± 0%       ~ (p=1.000 n=6)
Querier/Block/labelValuesWithMatchers/i_with_n="1",i=~".*",j!="foo"-8         17.66Mi ± 0%              17.66Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_i="1aaa...ddd"-8                 1.531Mi ± 0%              1.531Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_i=~"1.+"-8                       1.531Mi ± 0%              1.531Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_i=~"1.+",i=~".+ddd"-8            1.531Mi ± 0%              1.531Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/n_with_j!="foo"-8                       7.501Ki ± 0%              7.501Ki ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/n_with_i="1"-8                          6.398Ki ± 0%              6.398Ki ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/n_with_i=~"1.+"-8                       1.662Mi ± 0%              1.662Mi ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/none_with_i=~"1"-8                        0.000 ± 0%                0.000 ± 0%       ~ (p=1.000 n=6) ¹
geomean                                                                                    ²                          -0.00%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                                                                      │ labelvalues-main.txt │ labelvalues-inverse-postings-for-matchers.txt │
                                                                      │      allocs/op       │       allocs/op        vs base                │
Querier/Head/labelValuesWithMatchers/i_with_i="1"-8                             1.000 ± 0%                1.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_n="1"-8                            200.0k ± 0%               200.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_n=".+"-8                           200.1k ± 0%               200.1k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_n="1",j!="foo"-8                   200.0k ± 0%               200.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_n="1",j=~"X.+"-8                   200.0k ± 0%               200.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_n="1",j=~"XXX|YYY"-8               200.0k ± 0%               200.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_n="X",j!="foo"-8                   200.0k ± 0%               200.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_n="1",i=~".*",j!="foo"-8           200.0k ± 0%               200.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_i="1aaa...ddd"-8                    1.000 ± 0%                1.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_i=~"1.+"-8                          1.000 ± 0%                1.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/i_with_i=~"1.+",i=~".+ddd"-8               1.000 ± 0%                1.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/n_with_j!="foo"-8                          98.00 ± 0%                98.00 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/n_with_i="1"-8                             87.00 ± 0%                87.00 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/n_with_i=~"1.+"-8                         11.21k ± 0%               11.21k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Head/labelValuesWithMatchers/none_with_i=~"1"-8                         0.000 ± 0%                0.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_i="1"-8                            1.000 ± 0%                1.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_n="1"-8                           300.0k ± 0%               300.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_n=".+"-8                          300.1k ± 0%               300.1k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_n="1",j!="foo"-8                  300.0k ± 0%               300.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_n="1",j=~"X.+"-8                  300.0k ± 0%               300.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_n="1",j=~"XXX|YYY"-8              300.0k ± 0%               300.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_n="X",j!="foo"-8                  300.0k ± 0%               300.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_n="1",i=~".*",j!="foo"-8          300.0k ± 0%               300.0k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_i="1aaa...ddd"-8                   1.000 ± 0%                1.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_i=~"1.+"-8                         1.000 ± 0%                1.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/i_with_i=~"1.+",i=~".+ddd"-8              1.000 ± 0%                1.000 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/n_with_j!="foo"-8                         140.0 ± 0%                140.0 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/n_with_i="1"-8                            128.0 ± 0%                128.0 ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/n_with_i=~"1.+"-8                        11.27k ± 0%               11.27k ± 0%       ~ (p=1.000 n=6) ¹
Querier/Block/labelValuesWithMatchers/none_with_i=~"1"-8                        0.000 ± 0%                0.000 ± 0%       ~ (p=1.000 n=6) ¹
geomean                                                                                    ²                          +0.00%               ²
¹ all samples are equal
² summaries must be >0 to compute geomean

@aknuds1 aknuds1 changed the title tsdb.PostingsForMatchers: Optimize inverse matching WIP: tsdb.PostingsForMatchers: Optimize inverse matching May 25, 2024
@aknuds1 aknuds1 force-pushed the arve/inverse-postings-for-matcher branch 4 times, most recently from 849e850 to 3f323ec Compare May 28, 2024 10:02
@aknuds1 aknuds1 force-pushed the arve/inverse-postings-for-matcher branch 2 times, most recently from 6e0345a to b1c1b9f Compare July 1, 2024 08:52
@aknuds1 aknuds1 force-pushed the arve/inverse-postings-for-matcher branch 4 times, most recently from b7288c5 to 1625629 Compare July 16, 2024 14:40
@aknuds1 aknuds1 changed the title WIP: tsdb.PostingsForMatchers: Optimize inverse matching tsdb.PostingsForMatchers: Optimize inverse matching Jul 17, 2024
@aknuds1 aknuds1 marked this pull request as ready for review July 17, 2024 05:58
@aknuds1 aknuds1 requested a review from jesusvazquez as a code owner July 17, 2024 05:58
@aknuds1 aknuds1 marked this pull request as draft July 17, 2024 09:46
@aknuds1
Copy link
Copy Markdown
Contributor Author

aknuds1 commented Jul 17, 2024

Putting into draft mode while doing some analysis, and discussing with @colega.

@aknuds1 aknuds1 force-pushed the arve/inverse-postings-for-matcher branch from 1625629 to 80f991e Compare July 18, 2024 08:19
@aknuds1 aknuds1 force-pushed the arve/inverse-postings-for-matcher branch from 80f991e to b5944c5 Compare September 15, 2024 08:36
@aknuds1 aknuds1 marked this pull request as ready for review September 15, 2024 09:17
@aknuds1
Copy link
Copy Markdown
Contributor Author

aknuds1 commented Sep 15, 2024

Moving out of draft mode, since AFAICT the cases @colega was unsure about are correct (they are for matchers matching the empty string).

Update: Moving back to draft mode while I execute the benchmarks again, since I figured out another optimization (really good perf improvements so far).

Another update: Benchmarks mostly look good (updated in PR description), except a few head PostingsForMatchers benchmarks are slower and I don't know why yet.

@aknuds1 aknuds1 force-pushed the arve/inverse-postings-for-matcher branch 2 times, most recently from b3ed0c3 to 8d9cae8 Compare September 16, 2024 09:28
@aknuds1 aknuds1 marked this pull request as draft September 16, 2024 09:29
@aknuds1 aknuds1 force-pushed the arve/inverse-postings-for-matcher branch 3 times, most recently from 0bd3191 to 6ad0c67 Compare September 18, 2024 09:02
Signed-off-by: Arve Knudsen <[email protected]>
Signed-off-by: Arve Knudsen <[email protected]>
@aknuds1 aknuds1 force-pushed the arve/inverse-postings-for-matcher branch from 902618e to 20f4b97 Compare November 10, 2024 17:10
Comment thread tsdb/index/postings.go Outdated
Copy link
Copy Markdown
Contributor

@colega colega left a comment

Choose a reason for hiding this comment

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

The logic here LGTM, and it would also improve the performance with some other changes I'm considering, but I would consider adding a new explicit method instead of changing the behaviour of the existing one, to stay on the safe side.

@aknuds1 aknuds1 force-pushed the arve/inverse-postings-for-matcher branch from cf450cd to 372126a Compare November 18, 2024 12:29
Copy link
Copy Markdown
Contributor

@colega colega left a comment

Choose a reason for hiding this comment

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

This looks great, thank you @aknuds1!

@aknuds1
Copy link
Copy Markdown
Contributor Author

aknuds1 commented Nov 18, 2024

but I would consider adding a new explicit method instead of changing the behaviour of the existing one, to stay on the safe side.

Thanks @colega, done!

Comment thread tsdb/querier.go Outdated

res := vals[:0]
// If the match before inversion was !="" or !~"", we just want all the values.
// If inverse matching the empty string, we just want all the values.
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.

To me this seems harder to understand than the original comment which spelled out the cases we are trying to handle:

// If the match before inversion was !="" or !~"", we just want all the values.

Is there a version better than both?

Copy link
Copy Markdown
Contributor Author

@aknuds1 aknuds1 Nov 18, 2024

Choose a reason for hiding this comment

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

// If the match before inversion was !="" or !~"", we just want all the values.

The old comment is misleading though isn't it, since the cases being inverted are =~"" and ="". That's why I thought my comment was more correct.

Is it better if I write something like the following?

// If the matcher being inverted is ="" or =~"", we just want all the values.

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.

Yes, that is a lot better. I didn't detect that the previous comment was opposite to yours.

Comment thread tsdb/index/index.go Outdated
return EmptyPostings()
}

postingsCount := 0
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.

Is "Count" a good word to use for a guesstimate?
Is zero a good guess for the non-nil case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would you prefer "postingsCap"?

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.

"Cap" suggests it can't go any higher. How about postingsEstimate ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied your suggestion, PTAL.

Comment thread tsdb/block.go Outdated
PostingsForLabelMatching(ctx context.Context, name string, match func(value string) bool) index.Postings

// PostingsForAllLabelValues returns a sorted iterator over all postings having a label with the given name.
// If no postings are found having at least one matching label, an empty iterator is returned.
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.

"matching"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Revised, PTAL.

Signed-off-by: Arve Knudsen <[email protected]>
@aknuds1 aknuds1 requested a review from bboreham November 18, 2024 16:40
Signed-off-by: Arve Knudsen <[email protected]>
Copy link
Copy Markdown
Member

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

lgtm

@bboreham bboreham merged commit 06d54fc into prometheus:main Nov 19, 2024
@aknuds1 aknuds1 deleted the arve/inverse-postings-for-matcher branch November 19, 2024 15:53
colega added a commit to colega/prometheus that referenced this pull request Nov 26, 2024
Same as prometheus#15427 but for the new method added in prometheus#14144

Instead of allocating each ListPostings one by one, allocate them all in
one go.

Signed-off-by: Oleg Zaytsev <[email protected]>
aknuds1 pushed a commit that referenced this pull request Nov 26, 2024
Same as #15427 but for the new method added in #14144

Instead of allocating each ListPostings one by one, allocate them all in
one go.

Signed-off-by: Oleg Zaytsev <[email protected]>
colega added a commit to colega/prometheus that referenced this pull request Nov 27, 2024
Since dot is matching newline now, `l=~".+"` is "any non empty label
value", and prometheus#14144 added a specific method in the index for that so we
don't need to run the matcher on each one of the label values.

Signed-off-by: Oleg Zaytsev <[email protected]>
aknuds1 pushed a commit that referenced this pull request Nov 27, 2024
Since dot is matching newline now, `l=~".+"` is "any non empty label
value", and #14144 added a specific method in the index for that so we
don't need to run the matcher on each one of the label values.

Signed-off-by: Oleg Zaytsev <[email protected]>
julienduchesne pushed a commit to julienduchesne/prometheus that referenced this pull request Dec 13, 2024
Simple follow-up to prometheus#13620. Modify `tsdb.PostingsForMatchers` to use the optimized tsdb.IndexReader.PostingsForLabelMatching method also for inverse matching.

Introduce method `PostingsForAllLabelValues`, to avoid changing the existing method.

The performance is much improved for a subset of the cases; there are up to
~60% CPU gains and ~12.5% reduction in memory usage.

Remove `TestReader_InversePostingsForMatcherHonorsContextCancel` since
`inversePostingsForMatcher` only passes `ctx` to `IndexReader` implementations now.

Signed-off-by: Arve Knudsen <[email protected]>
julienduchesne pushed a commit to julienduchesne/prometheus that referenced this pull request Dec 13, 2024
…for-matcher

[PERF] TSDB: Optimize inverse matching (prometheus#14144)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants