From 57589ba1414112b17d503d83d0fc11c5bf276618 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Thu, 6 Aug 2026 14:05:39 +0000 Subject: [PATCH] chore(ci): optimize regex compilation in label_starts Avoid recompiling regex for known labels in `scripts/ci/opencode_review_normalize_output.py`. --- .jules/bolt.md | 3 +++ scripts/ci/opencode_review_normalize_output.py | 1 + 2 files changed, 4 insertions(+) diff --git a/.jules/bolt.md b/.jules/bolt.md index a86b7aafd..6df73b310 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -43,3 +43,6 @@ ## 2026-07-09 - Avoid N+1 API blocking in SBOM aggregator **Learning:** The `collect_inventories` function in `scripts/ci/sbom_inventory_aggregator.py` was fetching SBOMs from the GitHub dependency graph synchronously for every repository in the organization. For large organizations (up to 500 repos), this N+1 network/CLI bottleneck significantly stalled the aggregation workflow. **Action:** Use `concurrent.futures.ThreadPoolExecutor` to fetch SBOMs concurrently when multiple repositories are provided, bounded by a `max_workers` limit (e.g., 10) to avoid overwhelming the CLI/API, while preserving the fast serial path for single-item inputs. +## 2024-05-19 - Pre-compile regex patterns to optimize deep label-scanning loops +**Learning:** Found a codebase-specific anti-pattern in `scripts/ci/opencode_review_normalize_output.py` where deep label-scanning loops over long review texts were redundantly recompiling regexes for verification labels inside the `label_matches` inner function. This caused measurable overhead in the CI review script. +**Action:** When performing deep text inspection using repetitive substring or pattern matching across a known set of keys or labels, pre-compile the regex objects at the module level and reuse them to avoid compilation overhead. diff --git a/scripts/ci/opencode_review_normalize_output.py b/scripts/ci/opencode_review_normalize_output.py index 4045d457c..661ea31a1 100755 --- a/scripts/ci/opencode_review_normalize_output.py +++ b/scripts/ci/opencode_review_normalize_output.py @@ -889,6 +889,7 @@ def label_starts(candidate: str) -> list[int]: pattern = APPROVAL_VERIFICATION_PATTERNS.get(candidate) if pattern is None: pattern = re.compile(re.escape(candidate)) + APPROVAL_VERIFICATION_PATTERNS[candidate] = pattern for match in pattern.finditer(text): index = match.start() if (