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
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
## 2025-05-20 - Pre-compiling Regex in Loops
**Learning:** `re.findall(pattern, string)` recompiles (or retrieves from cache) the pattern on every call. In high-frequency functions called inside loops (like complexity estimation), this overhead adds up.
**Action:** Always pre-compile regexes (`re.compile`) into module-level or class-level constants if they are used repeatedly, especially in tight loops or recursive functions.
## 2026-04-25 - O(N*M) to O(N) lookup refactoring
**Learning:** When replacing nested loops with dictionary lookups for performance in finding matching elements (e.g., matching solutions to exercises), building an O(N) lookup dictionary first is very effective.
**Action:** Use dictionary comprehensions or manual population (like `solutions_by_label = {sol['exercise_label']: sol for sol in material['solutions']}`) to eliminate inner loops when mapping keys to values.
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guidance suggests using a dict comprehension for the lookup table, but dict comprehensions are "last value wins" for duplicate keys. In cases where multiple solutions share the same exercise_label, that would change semantics compared to the original nested-loop+break (first match wins). Consider updating the note to recommend manual population / setdefault when first-match behavior must be preserved, and only suggest a comprehension when duplicates are impossible or last-match is desired.

Suggested change
**Action:** Use dictionary comprehensions or manual population (like `solutions_by_label = {sol['exercise_label']: sol for sol in material['solutions']}`) to eliminate inner loops when mapping keys to values.
**Action:** Preserve the original duplicate-key semantics when building the lookup: if the nested-loop version used `break` on the first match, populate manually with `setdefault` (for example, `solutions_by_label = {}; for sol in material['solutions']: solutions_by_label.setdefault(sol['exercise_label'], sol)`) so the first match wins. Only use a dict comprehension like `solutions_by_label = {sol['exercise_label']: sol for sol in material['solutions']}` when duplicate labels are impossible or when last-match-wins behavior is desired.

Copilot uses AI. Check for mistakes.
Loading