Skip to content

searcher: optimize capture groups

Administrator requested to merge k/capture-groups-opt into main

Created by: keegancsmith

Capture groups are slow in go's regexp engine. However, we don't ever use the group captures so we can instead convert the groups into non-capturing groups. We do this by zoekt's OptimizeRegexp function which currently only does this transformation. However, it we plan on it containing more optimizations targetted at the text search use case in the future.

Test Plan: go test and benchmarks. Benchmarks didn't change, except for the new benchmark which uses capture groups

name                                old time/op    new time/op    delta
SearchRegex_large_capture_group-32     205ms ±12%     183ms ±16%  -11.04%  (p=0.008 n=9+10)
SearchRegex_small_capture_group-32    4.31ms ± 5%    3.71ms ± 3%  -14.00%  (p=0.000 n=9+8)

name                                old alloc/op   new alloc/op   delta
SearchRegex_large_capture_group-32    3.11MB ± 1%    2.98MB ± 1%   -4.22%  (p=0.000 n=9+10)
SearchRegex_small_capture_group-32    16.1kB ± 1%    15.7kB ± 1%   -2.61%  (p=0.000 n=9+8)

name                                old allocs/op  new allocs/op  delta
SearchRegex_large_capture_group-32     18.1k ± 0%     18.1k ± 0%     ~     (p=0.051 n=8+10)
SearchRegex_small_capture_group-32       193 ± 0%       193 ± 0%     ~     (all equal)

Merge request reports

Loading