Skip to content

⚡ Bolt: Replace O(N*M) nested loop with O(N) hash map lookup#107

Open
glacy wants to merge 1 commit into
mainfrom
bolt-optimize-onm-loop-1213647007545418317
Open

⚡ Bolt: Replace O(N*M) nested loop with O(N) hash map lookup#107
glacy wants to merge 1 commit into
mainfrom
bolt-optimize-onm-loop-1213647007545418317

Conversation

@glacy
Copy link
Copy Markdown
Owner

@glacy glacy commented May 19, 2026

💡 What: Replaced O(NM) nested list searches with an O(N) pre-computed lookup dictionary (sol_map) in MaterialExtractor.get_all_exercises and RAGIndexer.index_materials.
🎯 Why: When matching solutions to exercises across large materials, the inner loop iterated over the solutions array repeatedly for each exercise. This introduces an O(N
M) complexity which scales poorly as the number of exercises and solutions grows.
📊 Impact: Reduces solution lookup time from O(N*M) to O(N). Expected to significantly speed up material parsing and indexing phases for large documentation sets.
🔬 Measurement: Verified by running the existing test suite, which ensures that exercise-solution mapping semantics are fully preserved without regressions. Evaluated via unit testing logic mapping sol['exercise_label'] to exercise['label'].


PR created automatically by Jules for task 1213647007545418317 started by @glacy

Replaced an O(N*M) nested search loop with an O(N) pre-computed lookup dictionary to map solutions to exercises in material extraction and indexing.

Co-authored-by: glacy <1131951+glacy@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings May 19, 2026 18:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Replaces O(N*M) nested-loop solution-to-exercise matching with O(N) pre-computed dictionary lookups in MaterialExtractor.get_all_exercises and RAGIndexer.index_materials. The rest of the diff is Black/Ruff reformatting and an entry in .jules/bolt.md documenting the learning. First-match semantics are preserved via if key not in sol_map guards.

Changes:

  • Build a per-material sol_map once and replace inner search loops with sol_map.get(label) in two locations.
  • Apply Black formatting (string quotes, line wrapping, trailing commas) across both modules.
  • Add a learnings entry in .jules/bolt.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
evolutia/material_extractor.py Adds sol_map precomputation in get_all_exercises and reformatting.
evolutia/rag/rag_indexer.py Adds sol_map precomputation in index_materials and reformatting.
.jules/bolt.md Documents the O(N*M) → O(N) refactor learning.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants