Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Jules/bolt.md
Original file line number Diff line number Diff line change
@@ -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`.
12 changes: 8 additions & 4 deletions pipelines/orchestrator/quality/performance_auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down