From ff39893c3f5ce6c61a0756e7293ab7c247b14c4b Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Tue, 14 Jul 2026 17:51:07 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9A=A1=20Bolt:=20opencode=5Freview=5Fapp?= =?UTF-8?q?rove=5Fgate.sh=20=EC=A0=95=EA=B7=9C=EC=8B=9D=20=EC=B5=9C?= =?UTF-8?q?=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scripts/ci/opencode_review_approve_gate.sh에 내장된 Python 스크립트 내 루프 호출 함수(`changed_new_lines`)에서 매번 재컴파일되던 `hunk_header` 정규식을 모듈 레벨로 분리하고 `HUNK_HEADER_RE`로 미리 컴파일하도록 최적화했습니다. --- .jules/bolt.md | 3 +++ scripts/ci/opencode_review_approve_gate.sh | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index a86b7aaf..81c1abab 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. +## 2026-07-09 - Pre-compile Regex Patterns in Embedded Python Loop-called Functions +**Learning:** Found a regex recompilation bottleneck in `scripts/ci/opencode_review_approve_gate.sh` where `hunk_header = re.compile(...)` was defined inside the `changed_new_lines` inner Python function. Even when the outer Python execution is embedded in a shell script, recompiling a regex object inside a function called repetitively (like processing git diff lines for multiple files) incurs measurable overhead. +**Action:** Move inline regex compilation (using `re.compile()`) outside of loop-called functions to the module level, even when the Python script is embedded in a bash file (`cat << 'EOF' | python3`). Ensure global variables/constants are well documented. diff --git a/scripts/ci/opencode_review_approve_gate.sh b/scripts/ci/opencode_review_approve_gate.sh index bf21c0b4..5c157b3e 100755 --- a/scripts/ci/opencode_review_approve_gate.sh +++ b/scripts/ci/opencode_review_approve_gate.sh @@ -233,6 +233,11 @@ def normalized_line(value: str) -> str: return " ".join(value.strip().split()) +# ⚡ Bolt: Pre-compile regex at the module level to prevent recompilation in loop-called functions +# Impact: Reduces regex recompilation overhead when processing git diff hunk headers for every changed file +HUNK_HEADER_RE = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@") + + # ⚡ Bolt: Memoize changed_new_lines to prevent N+1 git diff subprocess calls # Impact: Substantially reduces I/O wait overhead when multiple findings are on the same file path @functools.cache @@ -265,9 +270,8 @@ def changed_new_lines(path_value: str) -> frozenset[int]: return frozenset() line_numbers: set[int] = set() - hunk_header = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@") for raw_line in completed.stdout.splitlines(): - match = hunk_header.match(raw_line) + match = HUNK_HEADER_RE.match(raw_line) if not match: continue start = int(match.group(1)) From 69305871ab96fd8bfc78defdbfeb9a16577978ce Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Tue, 14 Jul 2026 18:53:08 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=E2=9A=A1=20Bolt:=20opencode=5Freview=5Fapp?= =?UTF-8?q?rove=5Fgate.sh=20=EC=A0=95=EA=B7=9C=EC=8B=9D=20=EC=B5=9C?= =?UTF-8?q?=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scripts/ci/opencode_review_approve_gate.sh에 내장된 Python 스크립트 내 루프 호출 함수(`changed_new_lines`)에서 매번 재컴파일되던 `hunk_header` 정규식을 모듈 레벨로 분리하고 `HUNK_HEADER_RE`로 미리 컴파일하도록 최적화했습니다. 또한 해당 변경과 무관하게 실패하고 있던 `test_opencode_existing_approval_gate.py` 내의 artifact 권한 문제(테스트 셋업 중 chmod 누락)도 수정하여 전체 CI가 성공하도록 조치했습니다. --- tests/test_opencode_existing_approval_gate.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_opencode_existing_approval_gate.py b/tests/test_opencode_existing_approval_gate.py index 7602b2a1..f8b89f3b 100644 --- a/tests/test_opencode_existing_approval_gate.py +++ b/tests/test_opencode_existing_approval_gate.py @@ -61,6 +61,9 @@ def trusted_adversarial_artifacts(tmp_path, monkeypatch): ), encoding="utf-8", ) + changed_files.chmod(0o600) + manifest.chmod(0o600) + monkeypatch.setenv("RUNNER_TEMP", str(runner_temp)) monkeypatch.setenv("OPENCODE_SOURCE_WORKDIR", str(source_root)) monkeypatch.setenv("OPENCODE_CHANGED_FILES_FILE", str(changed_files)) From d505d2e61d9d71f1d4be9fd63f54bf4faba3a8e4 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Tue, 14 Jul 2026 19:34:09 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9A=A1=20Bolt:=20opencode=5Freview=5Fapp?= =?UTF-8?q?rove=5Fgate.sh=20=EC=A0=95=EA=B7=9C=EC=8B=9D=20=EC=B5=9C?= =?UTF-8?q?=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scripts/ci/opencode_review_approve_gate.sh에 내장된 Python 스크립트 내 루프 호출 함수(changed_new_lines)에서 매번 재컴파일되던 hunk_header 정규식을 모듈 레벨로 분리하고 HUNK_HEADER_RE로 미리 컴파일하도록 최적화했습니다. 또한 해당 변경과 무관하게 실패하고 있던 test_opencode_existing_approval_gate.py 내의 artifact 권한 문제(테스트 셋업 중 chmod 누락)도 수정하여 전체 CI가 성공하도록 조치했습니다. From a5dc89d4daa781e45b348471fd0b144fc14c5e37 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Tue, 14 Jul 2026 20:12:11 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=E2=9A=A1=20Bolt:=20opencode=5Freview=5Fapp?= =?UTF-8?q?rove=5Fgate.sh=20=EC=A0=95=EA=B7=9C=EC=8B=9D=20=EC=B5=9C?= =?UTF-8?q?=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scripts/ci/opencode_review_approve_gate.sh에 내장된 Python 스크립트 내 루프 호출 함수(changed_new_lines)에서 매번 재컴파일되던 hunk_header 정규식을 모듈 레벨로 분리하고 HUNK_HEADER_RE로 미리 컴파일하도록 최적화했습니다. 또한 해당 변경과 무관하게 실패하고 있던 test_opencode_existing_approval_gate.py 내의 artifact 권한 문제(테스트 셋업 중 chmod 누락)도 수정하여 전체 CI가 성공하도록 조치했습니다.