Skip to content

perf(formatters): hoist SCP git URL regex to package level in IsValidGitURL#446

Merged
SUSTAPLE117 merged 1 commit into
boostsecurityio:mainfrom
matiasinsaurralde:perf/formatters-isvalidgiturl
Jul 3, 2026
Merged

perf(formatters): hoist SCP git URL regex to package level in IsValidGitURL#446
SUSTAPLE117 merged 1 commit into
boostsecurityio:mainfrom
matiasinsaurralde:perf/formatters-isvalidgiturl

Conversation

@matiasinsaurralde

Copy link
Copy Markdown
Contributor

Summary

  • Move the SCP-style git URL regex (user@host:repo) from inside IsValidGitURL to a package-level var, so it is compiled once at init instead of on every call.
  • No behavior change for HTTP(S), ssh://, or SCP URL validation.

Benchmark

BenchmarkIsValidGitURL on Apple M4 Pro (darwin/arm64), 10 runs each:

URL type Before After Change
HTTPS ~113 ns, 1 alloc ~112 ns, 1 alloc unchanged (expected)
SSH-scheme ~150 ns, 2 allocs ~149 ns, 2 allocs unchanged (expected)
SCP ~2.6 µs, 5.6 KB, 75 allocs ~243 ns, 0 B, 0 allocs ~11× faster, zero heap allocs

The win is entirely on the SCP path (git@github.com:user/repo), which previously called regexp.MustCompile on every invocation.

…GitURL

Move regexp.MustCompile for SCP-style git URLs out of IsValidGitURL
so the pattern is compiled once at init instead of on every call.

Signed-off-by: Matías Insaurralde <matias@insaurral.de>
@matiasinsaurralde matiasinsaurralde requested a review from a team as a code owner July 3, 2026 03:11
@matiasinsaurralde matiasinsaurralde changed the title perf(sarif): hoist SCP git URL regex to package level in IsValidGitURL perf(formatters): hoist SCP git URL regex to package level in IsValidGitURL Jul 3, 2026
@fproulx-boostsecurity

Copy link
Copy Markdown
Contributor

Thanks @matiasinsaurralde LGTM

@SUSTAPLE117 SUSTAPLE117 merged commit a41f05a into boostsecurityio:main Jul 3, 2026
4 checks passed
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.

3 participants