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

@myukitty myukitty commented Aug 15, 2026

Copy link
Copy Markdown

When processing filters, Git commits, and Jira issue keys in loops or hot paths, compiling regular expressions on every iteration introduced unnecessary CPU and memory allocation overhead.

This PR:

  1. ResourceFilterOptions: Lazily compiles and caches include/exclude regexes using sync.Once, making concurrent ShouldInclude calls thread-safe and fast.
  2. GitView: Adds MatchRegexpInCommitMessageORBranchName(re *regexp.Regexp, ...) accepting a precompiled regex while maintaining backward-compatible MatchPatternInCommitMessageORBranchName(pattern, ...).
  3. Jira: Pre-compiles and caches Jira key patterns in a thread-safe sync.Map (getJiraKeyRegex) so both default and custom project key patterns avoid per-call compilation in FindJiraIssueKeys.
  4. Adds unit and concurrent tests in internal/filters/resourceFilter_test.go, internal/jira/jira_test.go, and internal/gitview/gitView_test.go.

Fixes #826.

Signed-off-by: myukitty <myukittyy@gmail.com>
@myukitty
myukitty force-pushed the perf/compile-regex-once branch from d65036d to 992d010 Compare August 17, 2026 17:45
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