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
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
## 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.

## 2024-05-18 - Replacing O(N*M) nested loops with O(N) map lookups
**Learning:** O(N*M) search loops across lists of exercises and solutions present a significant scaling bottleneck. While typical use cases may not feel slow with few materials, using large batches of files creates exponential time complexity. Refactoring logic into O(N) lookup maps is safer when duplicates exist in the mapped collection. A straight dict comprehension maps the *last* matched item if duplicates exist. Since the original implementation used `break` inside the nested loop (preserving the *first* matching solution), the solution must manually check `if key not in dict` to maintain precise functional parity.
**Action:** Always verify `break` vs. `continue` logic when refactoring O(N*M) loop searches into dictionary lookups. For `break` equivalents, ensure the first item mapping is populated and preserved by using explicit `not in` checks rather than list comprehensions, preserving behavioral equivalency with minimal performance overhead.
Loading