Skip to content

perf: compile regex patterns once instead of per-call in hot paths - #1098

Open
myukitty wants to merge 1 commit into
kosli-dev:mainfrom
myukitty:perf/compile-regex-once
Open

perf: compile regex patterns once instead of per-call in hot paths#1098
myukitty wants to merge 1 commit into
kosli-dev:mainfrom
myukitty:perf/compile-regex-once

Conversation

@myukitty

Copy link
Copy Markdown

Summary

Addresses #826 by compiling regular expressions once and reusing them across invocations in hot paths:

  1. internal/digest/digest.go (ValidateDigest):

    • Precompiled package-level validSha256CompiledRegex instead of compiling the static SHA256 validation pattern on every call.
    • Added BenchmarkValidateDigest.
  2. internal/filters/resourceFilter.go (ResourceFilterOptions):

    • Added cached compiled regex slices (compiledExclude, compiledInclude) and CompilePatterns() error method.
    • ShouldInclude compiles patterns once lazily on first invocation and reuses them across resource checks (e.g. iterating over namespaces/pods/functions/clusters).
    • Added unit tests for CompilePatterns and BenchmarkShouldInclude_Regex.
  3. internal/gitview/gitView.go (MatchPatternInCommitMessageORBranchName):

    • Added MatchRegexpInCommitMessageORBranchName taking a pre-compiled *regexp.Regexp.
    • Updated MatchPatternInCommitMessageORBranchName to safely compile via regexp.Compile and delegate without panicking.
    • Added unit tests.
  4. internal/jira/jira.go (FindJiraIssueKeys):

    • Precompiled static default Jira issue key pattern and dashDigitRegex.

Fixes #826.

Validation

  • go test -v -run TestFiltersSuite ./internal/filters: PASS
  • go test -v -run TestGitViewTestSuite ./internal/gitview: PASS
  • go test -v ./internal/jira: PASS
  • go test -v -run "TestDigestTestSuite/TestValidateDigest" ./internal/digest: PASS
  • go test -bench=Benchmark ./internal/digest ./internal/filters: PASS
  • go vet ./...: PASS (clean)
  • Independent review: ATD sealed pass (APPROVE, confidence 1.0)

Signed-off-by: myukitty <myukittyy@gmail.com>
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.

perf: compile regex patterns once instead of per-call in 3 hot paths

1 participant