Skip to content

perf: resolve scan/review pipeline performance bottlenecks (P2)#338

Open
ajianaz wants to merge 1 commit into
developfrom
fix/p2-performance-bottlenecks
Open

perf: resolve scan/review pipeline performance bottlenecks (P2)#338
ajianaz wants to merge 1 commit into
developfrom
fix/p2-performance-bottlenecks

Conversation

@ajianaz

@ajianaz ajianaz commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes 10 performance bottlenecks across the scan/review pipeline. All are "repeated work in loops" patterns — the fix is always the same: do it once outside the loop.

Fixes

# File Issue Fix
#41 src/engine/rules/matching.rs Regex recompiled per line Pre-compile regex once via ensure_compiled()
#5 src/mcp/tools.rs Per-file DB queries in nested loops Batch all symbols in single IN query
#13 src/main.rs Repeated graph lookups in Affected cmd Single batch query for all changed files
#14 src/main.rs Prepared statement in inner loop Prepare once before loop
#59 src/engine/secrets_scanner.rs No early cutoff after max_findings Break out of all loops when cap reached
#70 src/engine/context/extraction.rs Symbol cap only breaks inner loop Break all three nested loops
#67 src/engine/context/resolver.rs Repeated file reads from disk HashMap<PathBuf, String> cache
#3 src/mcp/tools.rs New Tokio runtime per MCP call Static LazyLock<Runtime>
#22 src/index/extract.rs Regex per detect_function_entry call static LazyLock<Regex> per language
#24 src/index/mod.rs Per-file transaction in prune_deleted Single transaction for all deletes

Testing

  • ✅ All 609 tests pass (cargo test)
  • ✅ Clippy clean (cargo clippy)
  • ✅ Formatted (cargo fmt)

Refs #335

Fix 10 performance issues — all 'repeated work in loops' patterns:

#41 - Pre-compile regex patterns once per rule instead of per line
#5  - Batch DB queries in handle_find_affected_tests (single IN clause)
#13 - Batch symbol fetch for Affected command (single query)
#14 - Prepare SQL statement once outside test-pattern loop
#59 - Early cutoff in secrets scanner when max_findings reached
#70 - Break out of all loops when symbol cap hit per file
#67 - Cache file reads during sibling search in resolver
#3  - Reuse single Tokio runtime for MCP tool calls (static LazyLock)
#22 - Static LazyLock regexes in detect_function_entry
#24 - Single transaction for prune_deleted instead of per-file

Refs #335
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.

1 participant