Skip to content

perf(scanner): hoist parser regexps to package level#447

Open
matiasinsaurralde wants to merge 1 commit into
boostsecurityio:mainfrom
matiasinsaurralde:perf/hoist-parser-regexps
Open

perf(scanner): hoist parser regexps to package level#447
matiasinsaurralde wants to merge 1 commit into
boostsecurityio:mainfrom
matiasinsaurralde:perf/hoist-parser-regexps

Conversation

@matiasinsaurralde

Copy link
Copy Markdown
Contributor

Each repo scan rebuilt the five-parser slice inside its goroutine, running regexp.MustCompile five times per repo. The patterns are static and *regexp.Regexp is concurrency-safe, so this compilation was pure waste — 5·N recompiles for an N-repo org scan.

This hoists the five patterns to package-level vars, compiling them once.

Metric Before After Improvement
Time 9673 ns 57 ns 169× faster (−99.4%)
Bytes 30,424 B 120 B 254× less (−99.6%)
Allocs 255 6 42× fewer

Compile the five parser path patterns once at package init instead of
recompiling them in each parser constructor on every repo scan.

BenchmarkNewMemParsers: 9673ns→57ns (169x), 30424B→120B, 255→6 allocs.

Signed-off-by: Matías Insaurralde <matias@insaurral.de>
@matiasinsaurralde matiasinsaurralde requested a review from a team as a code owner July 7, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant