Skip to content

Searcher: reduce allocations for chunk matches

Warren Gifford requested to merge cc/reduce-allocs into main

Created by: camdencheek

While investigating performance of searcher, I noticed we're doing quite a few extra allocations. Each commit is self-contained with a description of the change and showed an improvement in the benchmarks. The benchmark stats below are compared to main. Not a huge win for timings, but massive wins for allocations, which might become more important for timings on a more memory-constrained system.

❯ benchstat -alpha 0.1 /tmp/baseline.txt /tmp/ranges_slices.txt
name                                             old time/op    new time/op    delta
SearchRegex_large_fixed-10                         6.32ms ± 2%    6.18ms ± 0%   -2.06%  (p=0.008 n=5+5)
SearchRegex_rare_fixed-10                          7.96ms ± 1%    7.71ms ± 1%   -3.03%  (p=0.008 n=5+5)
SearchRegex_large_fixed_casesensitive-10           4.03ms ± 0%    3.93ms ± 1%   -2.50%  (p=0.008 n=5+5)
SearchRegex_large_re_dotstar-10                     235ms ± 1%     218ms ± 1%   -7.19%  (p=0.008 n=5+5)
SearchRegex_large_re_common-10                     6.08ms ± 1%    5.91ms ± 1%   -2.82%  (p=0.008 n=5+5)
SearchRegex_large_re_anchor-10                     69.9ms ± 2%    69.6ms ± 1%     ~     (p=0.690 n=5+5)
SearchRegex_large_path/path_only-10                 304µs ± 0%     305µs ± 1%     ~     (p=0.548 n=5+5)
SearchRegex_large_path/content_only-10             6.92ms ± 2%    6.85ms ± 1%     ~     (p=0.151 n=5+5)
SearchRegex_large_path/both_path_and_content-10    7.01ms ± 2%    6.87ms ± 1%   -1.92%  (p=0.056 n=5+5)
SearchRegex_small_fixed-10                          134µs ± 0%     133µs ± 0%   -1.10%  (p=0.008 n=5+5)
SearchRegex_small_fixed_casesensitive-10           87.5µs ± 0%    78.5µs ± 7%  -10.28%  (p=0.008 n=5+5)
SearchRegex_small_re_dotstar-10                    2.28ms ± 1%    2.27ms ± 1%     ~     (p=0.690 n=5+5)
SearchRegex_small_re_common-10                     90.7µs ± 0%    87.9µs ± 0%   -3.05%  (p=0.016 n=4+5)
SearchRegex_small_re_anchor-10                      769µs ± 1%     770µs ± 2%     ~     (p=0.841 n=5+5)

name                                             old alloc/op   new alloc/op   delta
SearchRegex_large_fixed-10                         15.8MB ± 0%    15.7MB ± 0%   -0.90%  (p=0.008 n=5+5)
SearchRegex_rare_fixed-10                          15.9MB ± 0%    15.7MB ± 0%   -0.95%  (p=0.008 n=5+5)
SearchRegex_large_fixed_casesensitive-10            167kB ± 0%      10kB ± 0%  -94.06%  (p=0.008 n=5+5)
SearchRegex_large_re_dotstar-10                     685MB ± 0%     570MB ± 0%  -16.76%  (p=0.008 n=5+5)
SearchRegex_large_re_common-10                     7.74MB ± 0%    6.40MB ± 0%  -17.31%  (p=0.008 n=5+5)
SearchRegex_large_re_anchor-10                     5.01MB ± 0%    4.27MB ± 0%  -14.79%  (p=0.008 n=5+5)
SearchRegex_large_path/path_only-10                1.03kB ± 0%    1.03kB ± 0%     ~     (all equal)
SearchRegex_large_path/content_only-10              219kB ± 1%      51kB ± 0%  -76.90%  (p=0.008 n=5+5)
SearchRegex_large_path/both_path_and_content-10     219kB ± 0%      51kB ± 0%  -76.93%  (p=0.008 n=5+5)
SearchRegex_small_fixed-10                          365kB ± 1%     361kB ± 1%   -1.02%  (p=0.008 n=5+5)
SearchRegex_small_fixed_casesensitive-10           6.46kB ± 0%    4.71kB ± 0%  -27.02%  (p=0.008 n=5+5)
SearchRegex_small_re_dotstar-10                    4.52MB ± 0%    3.75MB ± 0%  -16.95%  (p=0.008 n=5+5)
SearchRegex_small_re_common-10                     44.7kB ± 0%    38.7kB ± 0%  -13.36%  (p=0.008 n=5+5)
SearchRegex_small_re_anchor-10                     19.8kB ± 0%    18.3kB ± 1%   -7.34%  (p=0.008 n=5+5)

name                                             old allocs/op  new allocs/op  delta
SearchRegex_large_fixed-10                          6.63k ± 0%     0.19k ± 1%  -97.17%  (p=0.008 n=5+5)
SearchRegex_rare_fixed-10                           7.09k ± 0%     0.49k ± 0%  -93.08%  (p=0.008 n=5+5)
SearchRegex_large_fixed_casesensitive-10            6.59k ± 0%     0.14k ± 0%  -97.91%  (p=0.008 n=5+5)
SearchRegex_large_re_dotstar-10                     6.13M ± 0%     4.51M ± 0%  -26.52%  (p=0.008 n=5+5)
SearchRegex_large_re_common-10                      74.8k ± 0%     50.6k ± 0%  -32.32%  (p=0.008 n=5+5)
SearchRegex_large_re_anchor-10                      54.5k ± 0%     37.9k ± 0%  -30.42%  (p=0.008 n=5+5)
SearchRegex_large_path/path_only-10                  20.0 ± 0%      20.0 ± 0%     ~     (all equal)
SearchRegex_large_path/content_only-10              7.03k ± 0%     0.46k ± 0%  -93.43%  (p=0.008 n=5+5)
SearchRegex_large_path/both_path_and_content-10     7.03k ± 0%     0.46k ± 0%  -93.43%  (p=0.008 n=5+5)
SearchRegex_small_fixed-10                            154 ± 0%        82 ± 0%  -46.75%  (p=0.008 n=5+5)
SearchRegex_small_fixed_casesensitive-10              146 ± 0%        74 ± 0%  -49.32%  (p=0.008 n=5+5)
SearchRegex_small_re_dotstar-10                     40.5k ± 0%     29.6k ± 0%  -26.81%  (p=0.008 n=5+5)
SearchRegex_small_re_common-10                        537 ± 0%       387 ± 0%  -27.93%  (p=0.008 n=5+5)
SearchRegex_small_re_anchor-10                        296 ± 0%       235 ± 0%  -20.61%  (p=0.008 n=5+5)

Test plan

Existing unit tests + benchmarks.

Merge request reports

Loading