diff --git a/.Jules/bolt.md b/.Jules/bolt.md new file mode 100644 index 00000000..130c9639 --- /dev/null +++ b/.Jules/bolt.md @@ -0,0 +1 @@ +## 2026-03-23 - AST Analysis O(1) Optimization | Learning: AST walks process thousands of nodes, making O(n) list lookups inside the loop very expensive. | Action: Replaced list membership checks with O(1) sets for `expensive_functions` and `expensive_attrs` to optimize `_find_expensive_operations`. diff --git a/pipelines/orchestrator/quality/performance_auditor.py b/pipelines/orchestrator/quality/performance_auditor.py index 21c8aa14..cb485a01 100644 --- a/pipelines/orchestrator/quality/performance_auditor.py +++ b/pipelines/orchestrator/quality/performance_auditor.py @@ -512,7 +512,9 @@ def _find_inefficient_list_operations(self, node: ast.AST) -> int: def _find_expensive_operations(self, node: ast.AST) -> int: """Find expensive operations that could benefit from caching.""" count = 0 - expensive_functions = ["sorted", "max", "min", "sum", "len"] + # ⚡ Bolt: Use O(1) sets instead of O(n) lists for membership testing + expensive_functions = {"sorted", "max", "min", "sum", "len"} + expensive_attrs = {"sort", "reverse", "split", "join"} for child in ast.walk(node): if isinstance(child, ast.Call): @@ -522,9 +524,11 @@ def _find_expensive_operations(self, node: ast.AST) -> int: ): # Check if it's called multiple times (simple heuristic) count += 1 - elif isinstance(child.func, ast.Attribute): - if child.func.attr in ["sort", "reverse", "split", "join"]: - count += 1 + elif ( + isinstance(child.func, ast.Attribute) + and child.func.attr in expensive_attrs + ): + count += 1 return count if count > 2 else 0 # Only flag if multiple expensive ops