Repository: prometheus/tsdb
Pull request #642 (2019-06-28 07:57:57)

Reuse Chunk Iterator
Want feedback if something like this would be acceptable. 

When there are millions of chunks to be parsed for a query, re-using the chunk iterator saves a lot of allocs and in my benchmark in cortex it shed up to `5+s` for a query. (I don't have an exact number of chunks as of now).


codesome: Pointing out the function which causes the allocs
https://github.com/prometheus/tsdb/blob/ee010e9fab65565d65d851ac0b5b908c3e215798/chunkenc/xor.go#L105-L113
codesome: > Reset should always work.

For `deletedIterator`, how would `Reset` work? Because it needs deleted intervals to be reset, but the argument takes only `[]byte`. If we generalise it to `interface{}`, it would end up taking more allocs.
brian-brazil: Sounds like this isn't quite the right abstraction then. How about something more type specific?
codesome: You mean to say have that method to the struct and deference the interface to the type in order to call that method when needed?
brian-brazil: Yes, it really depends on what the call site is.
brian-brazil: I would like to see what the benchmarks look like for this, as when I tested things like this previously it didn't help much.

Does this change any of the API semantics?
codesome: Tested on the same query and data as described in [this comment](https://github.com/prometheus/prometheus/pull/5707#issuecomment-505440230). Also the code changes that I made in cortex querier to benchmark this is exactly similar to what I did in `querier.go` in this PR.
```
benchmark                                                                                                                    old ns/op       new ns/op       delta
BenchmarkChunkQueryableFromTar/query=count(metric_name{label1="value1"}),from=1561346880,to=1561368480,step=15.000000-8     41026506987     39711348531     -3.21%

benchmark                                                                                                                    old allocs     new allocs     delta
BenchmarkChunkQueryableFromTar/query=count(metric_name{label1="value1"}),from=1561346880,to=1561368480,step=15.000000-8     6479152        3027294        -53.28%

benchmark                                                                                                                    old bytes      new bytes      delta
BenchmarkChunkQueryableFromTar/query=count(metric_name{label1="value1"}),from=1561346880,to=1561368480,step=15.000000-8     5500794632     5176138576     -5.90%
```

With repeated benchmarks, apparently, the gain in time seems to decrease. So it's mostly allocs and B.op.
codesome: > Does this change any of the API semantics?

I am not actually sure what you mean here.
codesome: > Does this change any of the API semantics?

I am not actually sure what you mean here.
brian-brazil: Currently a caller of this code can keep multiple of the returned iterators around, now it's only valid until the next Seek/Next.
codesome: > now it's only valid until the next Seek/Next.

I am setting the iterators while the iterator is being created https://github.com/prometheus/tsdb/blob/cef83448cdf1fd61850b870976786dddcd99dee7/querier.go#L1082
So I think it's valid as soon as it is created (given that it's created using `newChunkSeriesIterator`)
codesome: Now I am also re-using `deletedIterator`. What part about this doesn't feel right @brian-brazil ? 
codesome: I have come up with another way to re-use the iterator. `chunckenc.Chunk.Iterator` method now takes a `chunckenc.Iterator` interface as an argument for reuse.


codesome: Here are the benchmarks results from `querier_test.go`. Gains look very good.
(I had added `_QUERY_` in the benchmark names just to filter them out while benchmarking)

```
benchmark                                                                                                           old ns/op       new ns/op       delta
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=1-8                                                               590             569             -3.56%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=2-8                                                               19569           18776           -4.05%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=4-8                                                               59749           60039           +0.49%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=8-8                                                               142610          140847          -1.24%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=16-8                                                              316888          313602          -1.04%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=32-8                                                              667122          676740          +1.44%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=1-8                                                              3438            3470            +0.93%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=2-8                                                              201836          202394          +0.28%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=4-8                                                              624315          611551          -2.04%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=8-8                                                              1492600         1538144         +3.05%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=16-8                                                             3352596         3369200         +0.50%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=32-8                                                             7138450         7250505         +1.57%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=1-8                                                             32042           34434           +7.47%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=2-8                                                             2652699         2628293         -0.92%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=4-8                                                             7108238         7156686         +0.68%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=8-8                                                             16350934        16590527        +1.47%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=16-8                                                            35417471        37663485        +6.34%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=32-8                                                            82462448        87802078        +6.48%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=1-8                                                             66342           65381           -1.45%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=2-8                                                             7351277         7125886         -3.07%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=4-8                                                             17113133        16842988        -1.58%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=8-8                                                             34303035        34414091        +0.32%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=16-8                                                            81260443        78129754        -3.85%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=32-8                                                            191112631       187329946       -1.98%
Benchmark_QUERY_QueryIterator/nBlocks=20,nSeries=1000,numSamplesPerSeriesPerBlock=20000,overlap=0%-8                30255106067     29270769893     -3.25%
Benchmark_QUERY_QueryIterator/nBlocks=20,nSeries=1000,numSamplesPerSeriesPerBlock=20000,overlap=10%-8               36680627719     34706623458     -5.38%
Benchmark_QUERY_QueryIterator/nBlocks=20,nSeries=1000,numSamplesPerSeriesPerBlock=20000,overlap=30%-8               35136798400     34068513147     -3.04%
Benchmark_QUERY_QuerySeek/nBlocks=20,nSeries=100,numSamplesPerSeriesPerBlock=2000,overlap=0%-8                      21904544300     21784004981     -0.55%
Benchmark_QUERY_QuerySeek/nBlocks=20,nSeries=100,numSamplesPerSeriesPerBlock=2000,overlap=10%-8                     21015524464     19650149159     -6.50%
Benchmark_QUERY_QuerySeek/nBlocks=20,nSeries=100,numSamplesPerSeriesPerBlock=2000,overlap=30%-8                     19440209526     18507708682     -4.80%
Benchmark_QUERY_QuerySeek/nBlocks=20,nSeries=100,numSamplesPerSeriesPerBlock=2000,overlap=50%-8                     17843282394     17051646915     -4.44%
Benchmark_QUERY_SetMatcher/nSeries=1,nBlocks=1,cardinality=100,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8               6925            6533            -5.66%
Benchmark_QUERY_SetMatcher/nSeries=15,nBlocks=1,cardinality=100,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8              6257            6722            +7.43%
Benchmark_QUERY_SetMatcher/nSeries=15,nBlocks=1,cardinality=100,pattern="^(?:1|2|3)$"-8                             4061            4267            +5.07%
Benchmark_QUERY_SetMatcher/nSeries=1000,nBlocks=20,cardinality=100,pattern="^(?:1|2|3)$"-8                          34404           36346           +5.64%
Benchmark_QUERY_SetMatcher/nSeries=1000,nBlocks=20,cardinality=100,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8           67952           67583           -0.54%
Benchmark_QUERY_SetMatcher/nSeries=100000,nBlocks=1,cardinality=100000,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8       7450            7564            +1.53%
Benchmark_QUERY_SetMatcher/nSeries=500000,nBlocks=1,cardinality=500000,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8       7511            7287            -2.98%
Benchmark_QUERY_SetMatcher/nSeries=500000,nBlocks=10,cardinality=500000,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8      36871           37745           +2.37%
Benchmark_QUERY_SetMatcher/nSeries=1000000,nBlocks=1,cardinality=1000000,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8     6666            6870            +3.06%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:1000-8                              786763          793854          +0.90%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:1000-8                                   62147           60979           -1.88%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:1000-8                                63414           62392           -1.61%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:1000-8                               204348          201691          -1.30%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:10000-8                             7839960         7560464         -3.57%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:10000-8                                  613522          609988          -0.58%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:10000-8                               619666          615992          -0.59%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:10000-8                              1976484         1954284         -1.12%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:100000-8                                 6249908         5827577         -6.76%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:100000-8                              6248890         6065604         -2.93%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:100000-8                             20419819        19388314        -5.05%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:100000-8                            81240614        76138402        -6.28%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:1000-8                                127427          126007          -1.11%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:1000-8                               404199          407252          +0.76%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:1000-8                              1594091         1577783         -1.02%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:1000-8                                   123414          122675          -0.60%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:10000-8                             15487529        15358892        -0.83%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:10000-8                                  1210697         1197396         -1.10%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:10000-8                               1258582         1248341         -0.81%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:10000-8                              3946157         3857700         -2.24%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:100000-8                            160912042       152904279       -4.98%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:100000-8                                 12471616        11671109        -6.42%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:100000-8                              12535046        12272652        -2.09%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:100000-8                             40208765        38363683        -4.59%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:1000-8                                191581          188431          -1.64%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:1000-8                               607246          605858          -0.23%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:1000-8                              2369466         2332586         -1.56%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:1000-8                                   186001          181361          -2.49%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:10000-8                                  1791584         1771905         -1.10%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:10000-8                               1851621         1845958         -0.31%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:10000-8                              5900440         5903744         +0.06%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:10000-8                             23661840        22389031        -5.38%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:100000-8                              18815228        18028246        -4.18%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:100000-8                             61170319        59374400        -2.94%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:100000-8                            237264204       233592176       -1.55%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:100000-8                                 18295087        17186679        -6.06%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:1000-8                                62288           61414           -1.40%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:1000-8                             63979           63780           -0.31%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:1000-8                            206272          205941          -0.16%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:1000-8                           805181          811945          +0.84%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:10000-8                               603409          610280          +1.14%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:10000-8                            620463          638460          +2.90%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:10000-8                           1985935         1996830         +0.55%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:10000-8                          7737422         7691122         -0.60%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:100000-8                         78715757        79045750        +0.42%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:100000-8                              5957931         6051462         +1.57%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:100000-8                           6147556         6310573         +2.65%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:100000-8                          20180671        19747437        -2.15%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:1000-8                             127212          127867          +0.51%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:1000-8                            411690          409448          -0.54%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:1000-8                           1603397         1585106         -1.14%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:1000-8                                125107          123473          -1.31%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:10000-8                            1250849         1219257         -2.53%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:10000-8                           3904302         3949420         +1.16%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:10000-8                          15743470        15229312        -3.27%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:10000-8                               1204246         1198623         -0.47%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:100000-8                           12390745        12279056        -0.90%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:100000-8                          40818572        39392151        -3.49%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:100000-8                         158016813       151983943       -3.82%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:100000-8                              12282148        11831624        -3.67%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:1000-8                             189735          191538          +0.95%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:1000-8                            622765          618062          -0.76%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:1000-8                           2368069         2380782         +0.54%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:1000-8                                184007          187704          +2.01%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:10000-8                               1805457         1788331         -0.95%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:10000-8                            1876572         1823881         -2.81%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:10000-8                           5857024         5831304         -0.44%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:10000-8                          23104326        23148449        +0.19%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:100000-8                         237424906       229263271       -3.44%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:100000-8                              18322308        17906625        -2.27%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:100000-8                           18870691        18604585        -1.41%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:100000-8                          59617366        59806132        +0.32%

benchmark                                                                                                           old allocs     new allocs     delta
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=1-8                                                               7              7              +0.00%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=2-8                                                               213            213            +0.00%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=4-8                                                               624            624            +0.00%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=8-8                                                               1445           1445           +0.00%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=16-8                                                              3086           3086           +0.00%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=32-8                                                              6367           6367           +0.00%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=1-8                                                              7              7              +0.00%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=2-8                                                              2013           2013           +0.00%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=4-8                                                              6024           6024           +0.00%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=8-8                                                              14045          14045          +0.00%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=16-8                                                             30086          30086          +0.00%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=32-8                                                             62167          62167          +0.00%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=1-8                                                             7              7              +0.00%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=2-8                                                             20013          20013          +0.00%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=4-8                                                             60024          60024          +0.00%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=8-8                                                             140045         140045         +0.00%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=16-8                                                            300086         300086         +0.00%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=32-8                                                            620167         620167         +0.00%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=1-8                                                             7              7              +0.00%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=2-8                                                             40013          40013          +0.00%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=4-8                                                             120024         120024         +0.00%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=8-8                                                             280045         280045         +0.00%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=16-8                                                            600086         600086         +0.00%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=32-8                                                            1240167        1240167        +0.00%
Benchmark_QUERY_QueryIterator/nBlocks=20,nSeries=1000,numSamplesPerSeriesPerBlock=20000,overlap=0%-8                6858208        3539066        -48.40%
Benchmark_QUERY_QueryIterator/nBlocks=20,nSeries=1000,numSamplesPerSeriesPerBlock=20000,overlap=10%-8               6861484        3538208        -48.43%
Benchmark_QUERY_QueryIterator/nBlocks=20,nSeries=1000,numSamplesPerSeriesPerBlock=20000,overlap=30%-8               6859612        3538780        -48.41%
Benchmark_QUERY_QuerySeek/nBlocks=20,nSeries=100,numSamplesPerSeriesPerBlock=2000,overlap=0%-8                      134062571      130062575      -2.98%
Benchmark_QUERY_QuerySeek/nBlocks=20,nSeries=100,numSamplesPerSeriesPerBlock=2000,overlap=10%-8                     38289276       54884          -99.86%
Benchmark_QUERY_QuerySeek/nBlocks=20,nSeries=100,numSamplesPerSeriesPerBlock=2000,overlap=30%-8                     30689256       54859          -99.82%
Benchmark_QUERY_QuerySeek/nBlocks=20,nSeries=100,numSamplesPerSeriesPerBlock=2000,overlap=50%-8                     23089248       54859          -99.76%
Benchmark_QUERY_SetMatcher/nSeries=1,nBlocks=1,cardinality=100,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8               86             86             +0.00%
Benchmark_QUERY_SetMatcher/nSeries=15,nBlocks=1,cardinality=100,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8              86             86             +0.00%
Benchmark_QUERY_SetMatcher/nSeries=15,nBlocks=1,cardinality=100,pattern="^(?:1|2|3)$"-8                             56             56             +0.00%
Benchmark_QUERY_SetMatcher/nSeries=1000,nBlocks=20,cardinality=100,pattern="^(?:1|2|3)$"-8                          514            514            +0.00%
Benchmark_QUERY_SetMatcher/nSeries=1000,nBlocks=20,cardinality=100,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8           1019           1019           +0.00%
Benchmark_QUERY_SetMatcher/nSeries=100000,nBlocks=1,cardinality=100000,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8       86             86             +0.00%
Benchmark_QUERY_SetMatcher/nSeries=500000,nBlocks=1,cardinality=500000,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8       86             86             +0.00%
Benchmark_QUERY_SetMatcher/nSeries=500000,nBlocks=10,cardinality=500000,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8      529            529            +0.00%
Benchmark_QUERY_SetMatcher/nSeries=1000000,nBlocks=1,cardinality=1000000,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8     86             86             +0.00%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:1000-8                              482            394            -18.26%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:1000-8                                   44             36             -18.18%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:1000-8                                42             34             -19.05%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:1000-8                               130            106            -18.46%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:10000-8                             2166           1252           -42.20%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:10000-8                                  197            114            -42.13%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:10000-8                               195            112            -42.56%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:10000-8                              589            340            -42.28%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:100000-8                                 1700           867            -49.00%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:100000-8                              1698           865            -49.06%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:100000-8                             5098           2599           -49.02%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:100000-8                            18702          9537           -49.01%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:1000-8                                69             53             -23.19%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:1000-8                               217            169            -22.12%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:1000-8                              809            633            -21.76%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:1000-8                                   73             57             -21.92%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:10000-8                             4143           2317           -44.07%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:10000-8                                  376            210            -44.15%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:10000-8                               372            206            -44.62%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:10000-8                              1126           628            -44.23%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:100000-8                            37181          18852          -49.30%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:100000-8                                 3379           1713           -49.30%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:100000-8                              3375           1709           -49.36%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:100000-8                             10135          5137           -49.31%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:1000-8                                95             71             -25.26%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:1000-8                               301            229            -23.92%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:1000-8                              1125           861            -23.47%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:1000-8                                   100            76             -24.00%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:10000-8                                  553            304            -45.03%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:10000-8                               548            299            -45.44%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:10000-8                              1660           913            -45.00%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:10000-8                             6110           3370           -44.84%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:100000-8                              5051           2552           -49.48%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:100000-8                             15169          7672           -49.42%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:100000-8                            55650          28158          -49.40%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:100000-8                                 5056           2557           -49.43%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:1000-8                                50             42             -16.00%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:1000-8                             49             41             -16.33%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:1000-8                            151            127            -15.89%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:1000-8                           559            471            -15.74%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:10000-8                               203            120            -40.89%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:10000-8                            202            119            -41.09%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:10000-8                           610            361            -40.82%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:10000-8                          2243           1330           -40.70%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:100000-8                         18780          9615           -48.80%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:100000-8                              1706           873            -48.83%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:100000-8                           1705           872            -48.86%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:100000-8                          5119           2620           -48.82%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:1000-8                             83             67             -19.28%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:1000-8                            259            211            -18.53%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:1000-8                           963            787            -18.28%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:1000-8                                85             69             -18.82%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:10000-8                            386            220            -43.01%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:10000-8                           1168           670            -42.64%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:10000-8                          4298           2471           -42.51%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:10000-8                               388            222            -42.78%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:100000-8                           3389           1723           -49.16%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:100000-8                          10178          5179           -49.12%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:100000-8                         37337          19009          -49.09%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:100000-8                              3391           1725           -49.13%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:1000-8                             116            92             -20.69%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:1000-8                            364            292            -19.78%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:1000-8                           1356           1092           -19.47%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:1000-8                                118            94             -20.34%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:10000-8                               571            322            -43.61%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:10000-8                            569            320            -43.76%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:10000-8                           1723           976            -43.35%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:10000-8                          6342           3602           -43.20%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:100000-8                         55884          28391          -49.20%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:100000-8                              5074           2575           -49.25%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:100000-8                           5072           2573           -49.27%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:100000-8                          15233          7736           -49.22%

benchmark                                                                                                           old bytes       new bytes       delta
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=1-8                                                               168             168             +0.00%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=2-8                                                               6800            6800            +0.00%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=4-8                                                               20064           20064           +0.00%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=8-8                                                               46592           46592           +0.00%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=16-8                                                              99648           99648           +0.00%
Benchmark_QUERY_MergedSeriesSet/series=100,blocks=32-8                                                              205760          205760          +0.00%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=1-8                                                              168             168             +0.00%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=2-8                                                              64400           64400           +0.00%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=4-8                                                              192864          192864          +0.00%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=8-8                                                              449792          449792          +0.00%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=16-8                                                             963648          963648          +0.00%
Benchmark_QUERY_MergedSeriesSet/series=1000,blocks=32-8                                                             1991360         1991360         +0.00%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=1-8                                                             168             168             +0.00%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=2-8                                                             640400          640400          +0.00%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=4-8                                                             1920864         1920864         +0.00%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=8-8                                                             4481792         4481792         +0.00%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=16-8                                                            9603651         9603648         -0.00%
Benchmark_QUERY_MergedSeriesSet/series=10000,blocks=32-8                                                            19847360        19847360        +0.00%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=1-8                                                             168             168             +0.00%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=2-8                                                             1280400         1280400         +0.00%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=4-8                                                             3840864         3840864         +0.00%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=8-8                                                             8961792         8961792         +0.00%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=16-8                                                            19203652        19203657        +0.00%
Benchmark_QUERY_MergedSeriesSet/series=20000,blocks=32-8                                                            39687360        39687360        +0.00%
Benchmark_QUERY_QueryIterator/nBlocks=20,nSeries=1000,numSamplesPerSeriesPerBlock=20000,overlap=0%-8                578388416       260360888       -54.99%
Benchmark_QUERY_QueryIterator/nBlocks=20,nSeries=1000,numSamplesPerSeriesPerBlock=20000,overlap=10%-8               581336400       259972432       -55.28%
Benchmark_QUERY_QueryIterator/nBlocks=20,nSeries=1000,numSamplesPerSeriesPerBlock=20000,overlap=30%-8               579825552       260434080       -55.08%
Benchmark_QUERY_QuerySeek/nBlocks=20,nSeries=100,numSamplesPerSeriesPerBlock=2000,overlap=0%-8                      11047651632     10663651688     -3.48%
Benchmark_QUERY_QuerySeek/nBlocks=20,nSeries=100,numSamplesPerSeriesPerBlock=2000,overlap=10%-8                     3677498848      5266576         -99.86%
Benchmark_QUERY_QuerySeek/nBlocks=20,nSeries=100,numSamplesPerSeriesPerBlock=2000,overlap=30%-8                     2947896424      5245624         -99.82%
Benchmark_QUERY_QuerySeek/nBlocks=20,nSeries=100,numSamplesPerSeriesPerBlock=2000,overlap=50%-8                     2218296016      5245624         -99.76%
Benchmark_QUERY_SetMatcher/nSeries=1,nBlocks=1,cardinality=100,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8               5063            5062            -0.02%
Benchmark_QUERY_SetMatcher/nSeries=15,nBlocks=1,cardinality=100,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8              5067            5068            +0.02%
Benchmark_QUERY_SetMatcher/nSeries=15,nBlocks=1,cardinality=100,pattern="^(?:1|2|3)$"-8                             3281            3281            +0.00%
Benchmark_QUERY_SetMatcher/nSeries=1000,nBlocks=20,cardinality=100,pattern="^(?:1|2|3)$"-8                          21140           21140           +0.00%
Benchmark_QUERY_SetMatcher/nSeries=1000,nBlocks=20,cardinality=100,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8           46567           46552           -0.03%
Benchmark_QUERY_SetMatcher/nSeries=100000,nBlocks=1,cardinality=100000,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8       5032            5035            +0.06%
Benchmark_QUERY_SetMatcher/nSeries=500000,nBlocks=1,cardinality=500000,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8       4993            4994            +0.02%
Benchmark_QUERY_SetMatcher/nSeries=500000,nBlocks=10,cardinality=500000,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8      24205           24205           +0.00%
Benchmark_QUERY_SetMatcher/nSeries=1000000,nBlocks=1,cardinality=1000000,pattern="^(?:1|2|3|4|5|6|7|8|9|10)$"-8     4984            4984            +0.00%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:1000-8                              47890           39408           -17.71%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:1000-8                                   5096            4328            -15.07%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:1000-8                                4193            3425            -18.32%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:1000-8                               12909           10602           -17.87%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:10000-8                             290751          202816          -30.24%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:10000-8                                  27112           19144           -29.39%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:10000-8                               26215           18245           -30.40%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:10000-8                              79006           55083           -30.28%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:100000-8                                 242408          162440          -32.99%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:100000-8                              241529          161553          -33.11%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:100000-8                             725040          485084          -33.10%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:100000-8                            2661022         1780222         -33.10%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:1000-8                                6338            4801            -24.25%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:1000-8                               19571           14959           -23.57%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:1000-8                              72680           55727           -23.33%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:1000-8                                   7408            5872            -20.73%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:10000-8                             455366          279493          -38.62%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:10000-8                                  42096           26160           -37.86%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:10000-8                               41035           25095           -38.84%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:10000-8                              123716          75870           -38.67%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:100000-8                            4295388         2533997         -41.01%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:100000-8                                 390896          230960          -40.92%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:100000-8                              389866          229908          -41.03%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:100000-8                             1170328         690416          -41.01%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:1000-8                                8546            6242            -26.96%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:1000-8                               26426           19508           -26.18%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:1000-8                              98192           72745           -25.92%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:1000-8                                   9760            7456            -23.61%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:10000-8                                  57120           33216           -41.85%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:10000-8                               55919           32009           -42.76%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:10000-8                              168620          96847           -42.56%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:10000-8                             620629          356993          -42.48%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:100000-8                              538260          298334          -44.57%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:100000-8                             1615861         895992          -44.55%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:100000-8                            5931035         3289788         -44.53%
Benchmark_QUERY_Queries/Eq_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:100000-8                                 539424          299520          -44.47%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:1000-8                                5346            4563            -14.65%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:1000-8                             4437            3664            -17.42%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:1000-8                            13538           11198           -17.28%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:1000-8                           50256           41943           -16.54%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:10000-8                               27544           19481           -29.27%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:10000-8                            26699           18579           -30.41%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:10000-8                           80278           56090           -30.13%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:10000-8                          296486          207476          -30.02%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_10-Blocks_nSeries:10_nSamples:100000-8                         2675826         1789368         -33.13%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_Head_nSeries:10_nSamples:100000-8                              243673          163324          -32.97%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_1-Block_nSeries:10_nSamples:100000-8                           242625          162266          -33.12%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_1_3-Blocks_nSeries:10_nSamples:100000-8                          727767          487420          -33.03%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:1000-8                             6780            5202            -23.27%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:1000-8                            20727           16052           -22.56%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:1000-8                           77218           60074           -22.20%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:1000-8                                7792            6256            -19.71%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:10000-8                            41890           25649           -38.77%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:10000-8                           125853          77495           -38.42%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:10000-8                          463103          287179          -37.99%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:10000-8                               42771           26682           -37.62%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_1-Block_nSeries:10_nSamples:100000-8                           391676          231328          -40.94%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_3-Blocks_nSeries:10_nSamples:100000-8                          1174999         693818          -40.95%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_10-Blocks_nSeries:10_nSamples:100000-8                         4313792         2549528         -40.90%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_2_Head_nSeries:10_nSamples:100000-8                              393045          231977          -40.98%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:1000-8                             9137            6783            -25.76%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:1000-8                            28066           21127           -24.72%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:1000-8                           104336          79332           -23.96%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:1000-8                                10288           7972            -22.51%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:10000-8                               58075           34016           -41.43%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:10000-8                            56922           32784           -42.41%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:10000-8                           171814          99162           -42.29%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:10000-8                          633692          366290          -42.20%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_10-Blocks_nSeries:10_nSamples:100000-8                         5958625         3309766         -44.45%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_Head_nSeries:10_nSamples:100000-8                              542082          301046          -44.46%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_1-Block_nSeries:10_nSamples:100000-8                           540595          299910          -44.52%
Benchmark_QUERY_Queries/Regex_Matcher:_Expansion_-_3_3-Blocks_nSeries:10_nSamples:100000-8                          1622866         901095          -44.48%
```
brian-brazil: :+1: 
codesome: (Will hold off merging until 2.11.0 is out, just in case if there is a bugfix to be included from tsdb in the release)

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9d057a3..6708b48 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
 ## Master / unreleased
 
+ - [FEATURE] `chunckenc.Chunk.Iterator` method now takes a `chunckenc.Iterator` interface as an argument for reuse.
+
 ## 0.9.1
 
  - [CHANGE] LiveReader metrics are now injected rather than global.
@@ -19,6 +21,7 @@
  - [ENHANCEMENT] Reduced disk usage for WAL for small setups.
  - [ENHANCEMENT] Optimize queries using regexp for set lookups.
 
+
 ## 0.8.0
 
  - [BUGFIX] Calling `Close` more than once on a querier returns an error instead of a panic.
diff --git a/chunkenc/chunk.go b/chunkenc/chunk.go
index dc56660..5f9349f 100644
--- a/chunkenc/chunk.go
+++ b/chunkenc/chunk.go
@@ -44,7 +44,10 @@ type Chunk interface {
 	Bytes() []byte
 	Encoding() Encoding
 	Appender() (Appender, error)
-	Iterator() Iterator
+	// The iterator passed as argument is for re-use.
+	// Depending on implementation, the iterator can
+	// be re-used or a new iterator can be allocated.
+	Iterator(Iterator) Iterator
 	NumSamples() int
 }
 
diff --git a/chunkenc/xor.go b/chunkenc/xor.go
index 1518772..ca20309 100644
--- a/chunkenc/xor.go
+++ b/chunkenc/xor.go
@@ -77,7 +77,7 @@ func (c *XORChunk) NumSamples() int {
 
 // Appender implements the Chunk interface.
 func (c *XORChunk) Appender() (Appender, error) {
-	it := c.iterator()
+	it := c.iterator(nil)
 
 	// To get an appender we must know the state it would have if we had
 	// appended all existing data from scratch.
@@ -102,19 +102,25 @@ func (c *XORChunk) Appender() (Appender, error) {
 	return a, nil
 }
 
-func (c *XORChunk) iterator() *xorIterator {
+func (c *XORChunk) iterator(it Iterator) *xorIterator {
 	// Should iterators guarantee to act on a copy of the data so it doesn't lock append?
 	// When using striped locks to guard access to chunks, probably yes.
 	// Could only copy data if the chunk is not completed yet.
+	if xorIter, ok := it.(*xorIterator); ok {
+		xorIter.Reset(c.b.bytes())
+		return xorIter
+	}
 	return &xorIterator{
+		// The first 2 bytes contain chunk headers.
+		// We skip that for actual samples.
 		br:       newBReader(c.b.bytes()[2:]),
 		numTotal: binary.BigEndian.Uint16(c.b.bytes()),
 	}
 }
 
 // Iterator implements the Chunk interface.
-func (c *XORChunk) Iterator() Iterator {
-	return c.iterator()
+func (c *XORChunk) Iterator(it Iterator) Iterator {
+	return c.iterator(it)
 }
 
 type xorAppender struct {
@@ -243,6 +249,21 @@ func (it *xorIterator) Err() error {
 	return it.err
 }
 
+func (it *xorIterator) Reset(b []byte) {
+	// The first 2 bytes contain chunk headers.
+	// We skip that for actual samples.
+	it.br = newBReader(b[2:])
+	it.numTotal = binary.BigEndian.Uint16(b)
+
+	it.numRead = 0
+	it.t = 0
+	it.val = 0
+	it.leading = 0
+	it.trailing = 0
+	it.tDelta = 0
+	it.err = nil
+}
+
 func (it *xorIterator) Next() bool {
 	if it.err != nil || it.numRead == it.numTotal {
 		return false
diff --git a/chunks/chunks.go b/chunks/chunks.go
index 9ce8c57..7d1c57b 100644
--- a/chunks/chunks.go
+++ b/chunks/chunks.go
@@ -245,8 +245,8 @@ func MergeChunks(a, b chunkenc.Chunk) (*chunkenc.XORChunk, error) {
 	if err != nil {
 		return nil, err
 	}
-	ait := a.Iterator()
-	bit := b.Iterator()
+	ait := a.Iterator(nil)
+	bit := b.Iterator(nil)
 	aok, bok := ait.Next(), bit.Next()
 	for aok && bok {
 		at, av := ait.At()
diff --git a/compact.go b/compact.go
index e19b7ed..6df0256 100644
--- a/compact.go
+++ b/compact.go
@@ -736,6 +736,7 @@ func (c *LeveledCompactor) populateBlock(blocks []BlockReader, meta *BlockMeta,
 		return errors.Wrap(err, "add symbols")
 	}
 
+	delIter := &deletedIterator{}
 	for set.Next() {
 		select {
 		case <-c.ctx.Done():
@@ -788,17 +789,18 @@ func (c *LeveledCompactor) populateBlock(blocks []BlockReader, meta *BlockMeta,
 					return err
 				}
 
-				it := &deletedIterator{it: chk.Chunk.Iterator(), intervals: dranges}
+				delIter.it = chk.Chunk.Iterator(delIter.it)
+				delIter.intervals = dranges
 
 				var (
 					t int64
 					v float64
 				)
-				for it.Next() {
-					t, v = it.At()
+				for delIter.Next() {
+					t, v = delIter.At()
 					app.Append(t, v)
 				}
-				if err := it.Err(); err != nil {
+				if err := delIter.Err(); err != nil {
 					return errors.Wrap(err, "iterate chunk while re-encoding")
 				}
 
diff --git a/head.go b/head.go
index 5e2eae8..8f513b4 100644
--- a/head.go
+++ b/head.go
@@ -1185,9 +1185,9 @@ type safeChunk struct {
 	cid int
 }
 
-func (c *safeChunk) Iterator() chunkenc.Iterator {
+func (c *safeChunk) Iterator(reuseIter chunkenc.Iterator) chunkenc.Iterator {
 	c.s.Lock()
-	it := c.s.iterator(c.cid)
+	it := c.s.iterator(c.cid, reuseIter)
 	c.s.Unlock()
 	return it
 }
@@ -1739,7 +1739,7 @@ func computeChunkEndTime(start, cur, max int64) int64 {
 	return start + (max-start)/a
 }
 
-func (s *memSeries) iterator(id int) chunkenc.Iterator {
+func (s *memSeries) iterator(id int, it chunkenc.Iterator) chunkenc.Iterator {
 	c := s.chunk(id)
 	// TODO(fabxc): Work around! A querier may have retrieved a pointer to a series' chunk,
 	// which got then garbage collected before it got accessed.
@@ -1749,17 +1749,23 @@ func (s *memSeries) iterator(id int) chunkenc.Iterator {
 	}
 
 	if id-s.firstChunkID < len(s.chunks)-1 {
-		return c.chunk.Iterator()
+		return c.chunk.Iterator(it)
 	}
 	// Serve the last 4 samples for the last chunk from the sample buffer
 	// as their compressed bytes may be mutated by added samples.
-	it := &memSafeIterator{
-		Iterator: c.chunk.Iterator(),
+	if msIter, ok := it.(*memSafeIterator); ok {
+		msIter.Iterator = c.chunk.Iterator(msIter.Iterator)
+		msIter.i = -1
+		msIter.total = c.chunk.NumSamples()
+		msIter.buf = s.sampleBuf
+		return msIter
+	}
+	return &memSafeIterator{
+		Iterator: c.chunk.Iterator(it),
 		i:        -1,
 		total:    c.chunk.NumSamples(),
 		buf:      s.sampleBuf,
 	}
-	return it
 }
 
 func (s *memSeries) head() *memChunk {
diff --git a/index/index.go b/index/index.go
index 6b333fa..c18f77d 100644
--- a/index/index.go
+++ b/index/index.go
@@ -781,9 +781,13 @@ func ReadOffsetTable(bs ByteSlice, off uint64, f func([]string, uint64) error) e
 	d := encoding.NewDecbufAt(bs, int(off), castagnoliTable)
 	cnt := d.Be32()
 
+	// The Postings offset table takes only 2 keys per entry (name and value of label),
+	// and the LabelIndices offset table takes only 1 key per entry (a label name).
+	// Hence setting the size to max of both, i.e. 2.
+	keys := make([]string, 0, 2)
 	for d.Err() == nil && d.Len() > 0 && cnt > 0 {
 		keyCount := d.Uvarint()
-		keys := make([]string, 0, keyCount)
+		keys = keys[:0]
 
 		for i := 0; i < keyCount; i++ {
 			keys = append(keys, d.UvarintStr())
diff --git a/querier.go b/querier.go
index 253102b..fbd9493 100644
--- a/querier.go
+++ b/querier.go
@@ -1060,8 +1060,9 @@ func (it *verticalMergeSeriesIterator) Err() error {
 type chunkSeriesIterator struct {
 	chunks []chunks.Meta
 
-	i   int
-	cur chunkenc.Iterator
+	i          int
+	cur        chunkenc.Iterator
+	bufDelIter *deletedIterator
 
 	maxt, mint int64
 
@@ -1069,21 +1070,32 @@ type chunkSeriesIterator struct {
 }
 
 func newChunkSeriesIterator(cs []chunks.Meta, dranges Intervals, mint, maxt int64) *chunkSeriesIterator {
-	it := cs[0].Chunk.Iterator()
-
-	if len(dranges) > 0 {
-		it = &deletedIterator{it: it, intervals: dranges}
-	}
-	return &chunkSeriesIterator{
+	csi := &chunkSeriesIterator{
 		chunks: cs,
 		i:      0,
-		cur:    it,
 
 		mint: mint,
 		maxt: maxt,
 
 		intervals: dranges,
 	}
+	csi.resetCurIterator()
+
+	return csi
+}
+
+func (it *chunkSeriesIterator) resetCurIterator() {
+	if len(it.intervals) == 0 {
+		it.cur = it.chunks[it.i].Chunk.Iterator(it.cur)
+		return
+	}
+	if it.bufDelIter == nil {
+		it.bufDelIter = &deletedIterator{
+			intervals: it.intervals,
+		}
+	}
+	it.bufDelIter.it = it.chunks[it.i].Chunk.Iterator(it.bufDelIter.it)
+	it.cur = it.bufDelIter
 }
 
 func (it *chunkSeriesIterator) Seek(t int64) (ok bool) {
@@ -1102,10 +1114,7 @@ func (it *chunkSeriesIterator) Seek(t int64) (ok bool) {
 		}
 	}
 
-	it.cur = it.chunks[it.i].Chunk.Iterator()
-	if len(it.intervals) > 0 {
-		it.cur = &deletedIterator{it: it.cur, intervals: it.intervals}
-	}
+	it.resetCurIterator()
 
 	for it.cur.Next() {
 		t0, _ := it.cur.At()
@@ -1145,10 +1154,7 @@ func (it *chunkSeriesIterator) Next() bool {
 	}
 
 	it.i++
-	it.cur = it.chunks[it.i].Chunk.Iterator()
-	if len(it.intervals) > 0 {
-		it.cur = &deletedIterator{it: it.cur, intervals: it.intervals}
-	}
+	it.resetCurIterator()
 
 	return it.Next()
 }


Test patch:
diff --git a/chunkenc/chunk_test.go b/chunkenc/chunk_test.go
index 11dc190..f6577b4 100644
--- a/chunkenc/chunk_test.go
+++ b/chunkenc/chunk_test.go
@@ -77,7 +77,7 @@ func testChunk(c Chunk) error {
 		// fmt.Println("appended", len(c.Bytes()), c.Bytes())
 	}
 
-	it := c.Iterator()
+	it := c.Iterator(nil)
 	var res []pair
 	for it.Next() {
 		ts, v := it.At()
@@ -133,9 +133,10 @@ func benchmarkIterator(b *testing.B, newChunk func() Chunk) {
 
 	res := make([]float64, 0, 1024)
 
+	var it Iterator
 	for i := 0; i < len(chunks); i++ {
 		c := chunks[i]
-		it := c.Iterator()
+		it := c.Iterator(it)
 
 		for it.Next() {
 			_, v := it.At()
diff --git a/head_test.go b/head_test.go
index 55067ea..040ae82 100644
--- a/head_test.go
+++ b/head_test.go
@@ -159,9 +159,9 @@ func TestHead_ReadWAL(t *testing.T) {
 				testutil.Ok(t, c.Err())
 				return x
 			}
-			testutil.Equals(t, []sample{{100, 2}, {101, 5}}, expandChunk(s10.iterator(0)))
-			testutil.Equals(t, []sample{{101, 6}}, expandChunk(s50.iterator(0)))
-			testutil.Equals(t, []sample{{100, 3}, {101, 7}}, expandChunk(s100.iterator(0)))
+			testutil.Equals(t, []sample{{100, 2}, {101, 5}}, expandChunk(s10.iterator(0, nil)))
+			testutil.Equals(t, []sample{{101, 6}}, expandChunk(s50.iterator(0, nil)))
+			testutil.Equals(t, []sample{{100, 3}, {101, 7}}, expandChunk(s100.iterator(0, nil)))
 		})
 	}
 }
@@ -313,11 +313,11 @@ func TestMemSeries_truncateChunks(t *testing.T) {
 
 	// Validate that the series' sample buffer is applied correctly to the last chunk
 	// after truncation.
-	it1 := s.iterator(s.chunkID(len(s.chunks) - 1))
+	it1 := s.iterator(s.chunkID(len(s.chunks)-1), nil)
 	_, ok := it1.(*memSafeIterator)
 	testutil.Assert(t, ok == true, "")
 
-	it2 := s.iterator(s.chunkID(len(s.chunks) - 2))
+	it2 := s.iterator(s.chunkID(len(s.chunks)-2), nil)
 	_, ok = it2.(*memSafeIterator)
 	testutil.Assert(t, ok == false, "non-last chunk incorrectly wrapped with sample buffer")
 }
@@ -451,10 +451,11 @@ func TestHeadDeleteSimple(t *testing.T) {
 
 						chunkr, err := h.Chunks()
 						testutil.Ok(t, err)
+						var ii chunkenc.Iterator
 						for _, meta := range chkMetas {
 							chk, err := chunkr.Chunk(meta.Ref)
 							testutil.Ok(t, err)
-							ii := chk.Iterator()
+							ii = chk.Iterator(ii)
 							for ii.Next() {
 								t, v := ii.At()
 								actSamples = append(actSamples, sample{t: t, v: v})
diff --git a/mocks_test.go b/mocks_test.go
index 243d5cf..aa84ff0 100644
--- a/mocks_test.go
+++ b/mocks_test.go
@@ -14,6 +14,7 @@
 package tsdb
 
 import (
+	"github.com/prometheus/tsdb/chunkenc"
 	"github.com/prometheus/tsdb/chunks"
 	"github.com/prometheus/tsdb/index"
 	"github.com/prometheus/tsdb/labels"
@@ -40,10 +41,11 @@ func (m *mockIndexWriter) AddSeries(ref uint64, l labels.Labels, chunks ...chunk
 		i = len(m.series) - 1
 	}
 
+	var iter chunkenc.Iterator
 	for _, chk := range chunks {
 		samples := make([]sample, 0, chk.Chunk.NumSamples())
 
-		iter := chk.Chunk.Iterator()
+		iter = chk.Chunk.Iterator(iter)
 		for iter.Next() {
 			s := sample{}
 			s.t, s.v = iter.At()
diff --git a/querier_test.go b/querier_test.go
index 252170d..2be48fc 100644
--- a/querier_test.go
+++ b/querier_test.go
@@ -1270,7 +1270,7 @@ func TestDeletedIterator(t *testing.T) {
 
 	for _, c := range cases {
 		i := int64(-1)
-		it := &deletedIterator{it: chk.Iterator(), intervals: c.r[:]}
+		it := &deletedIterator{it: chk.Iterator(nil), intervals: c.r[:]}
 		ranges := c.r[:]
 		for it.Next() {
 			i++