diff --git a/.jules/bolt.md b/.jules/bolt.md index a337772..6d4e7ed 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -22,3 +22,7 @@ ## 2024-06-16 - Parallelize Subprocess CLI Calls **Learning:** Sequential, synchronous execution of `subprocess.run` (like calling the GitHub CLI) across multiple items (like PRs) is a significant I/O bottleneck. **Action:** Use `concurrent.futures.ThreadPoolExecutor` with `functools.partial` and `executor.map` to safely parallelize I/O-bound subprocess executions, significantly reducing overall script runtime. + +## 2024-05-16 - Module-level Constants for Performance +**Learning:** Recreating static dictionaries (like severity mappings and icons) inside frequently called functions causes unnecessary memory allocations and slight performance overhead on every call. +**Action:** Extract static dictionaries to module-level constants to ensure they are instantiated only once when the module is loaded. diff --git a/scanner/cli/vibesec.py b/scanner/cli/vibesec.py index 89c5584..eddad2e 100644 --- a/scanner/cli/vibesec.py +++ b/scanner/cli/vibesec.py @@ -602,21 +602,24 @@ def _scan_file(file_path: Path, base_path: Path): return findings + +# ⚡ Bolt: Move severity mappings to module level to avoid redundant +# dictionary allocations on every call to print scan results. +SEVERITY_ORDER = {"CRITICAL": 0, "HIGH": 1, "WARNING": 2, "INFO": 3} +SEVERITY_ICONS = { + "CRITICAL": "🔴 CRITICAL", + "HIGH": "🟠 HIGH", + "WARNING": "🟡 WARNING", + "INFO": "🔵 INFO", +} + def _print_scan_results(findings, files_scanned): - severity_order = {"CRITICAL": 0, "HIGH": 1, "WARNING": 2, "INFO": 3} - findings.sort(key=lambda f: severity_order.get(f["severity"], 99)) - - severity_icons = { - "CRITICAL": "🔴 CRITICAL", - "HIGH": "🟠 HIGH", - "WARNING": "🟡 WARNING", - "INFO": "🔵 INFO", - } + findings.sort(key=lambda f: SEVERITY_ORDER.get(f["severity"], 99)) counts = {"CRITICAL": 0, "HIGH": 0, "WARNING": 0, "INFO": 0} for f in findings: counts[f["severity"]] += 1 - icon = severity_icons.get(f["severity"], f["severity"]) + icon = SEVERITY_ICONS.get(f["severity"], f["severity"]) print(f"[{icon}] {f['file']}:{f['line']}") print(f" Rule: {f['rule_id']}") print(f" {f['message']}")