⚡ Bolt: [performance improvement] Optimize MaterialExtractor iteration loops#94
⚡ Bolt: [performance improvement] Optimize MaterialExtractor iteration loops#94glacy wants to merge 1 commit into
Conversation
- Replaced O(N*M) nested loop in `get_all_exercises` with an O(N) hash map lookup, preserving original first-match behavior. - Hoisted redundant `topic.lower()` calls outside of the directory scanning loops in `extract_by_topic` to avoid repeated string allocations. Co-authored-by: glacy <1131951+glacy@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
This PR improves the performance of material parsing by optimizing solution lookup during exercise aggregation and reducing repeated string work in topic-based extraction. It also adjusts extract_from_file so successful results can be cached correctly.
Changes:
- Optimizes
get_all_exercises()by replacing the nested exercise→solution scan with a per-material dictionary lookup while preserving “first match wins” behavior. - Hoists
topic.lower()inextract_by_topic()to avoid redundant lowercasing during directory iteration. - Fixes result caching in
extract_from_file()and does some small refactors/formatting updates.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| evolutia/material_extractor.py | Performance improvements for solution resolution + minor refactors in caching and topic extraction paths. |
| evolutia.egg-info/SOURCES.txt | Adds tests/test_markdown_parser.py to the generated sources list. |
Comments suppressed due to low confidence (1)
evolutia/material_extractor.py:335
- La validez del caché se decide comparando
file_mtimecontra_last_scan_timestamp, pero nunca se usa eltimestampalmacenado enself._file_cache[file_path]ni el TTL (self._cache_ttl). Esto puede dejar el caché incorrecto/inefectivo (p.ej., TTL anunciado pero no aplicado). Sería más robusto comparar contra el mtime/timestamp guardado para ese archivo y/o invalidar por antigüedad usando_cache_ttl.
file_mtime = file_path.stat().st_mtime
# Usar el timestamp de escaneo más reciente para verificar
if file_mtime > self._last_scan_timestamp:
return False
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "data": result, | ||
| "timestamp": file_path.stat().st_mtime, | ||
| } | ||
| self._last_scan_timestamp = max(self._last_scan_timestamp, file_path.stat().st_mtime) | ||
| self._last_scan_timestamp = max( | ||
| self._last_scan_timestamp, file_path.stat().st_mtime |
| try: | ||
| cache_entry = self._file_cache[file_path] | ||
| _ = self._file_cache[file_path] | ||
| file_mtime = file_path.stat().st_mtime |
| tests/test_exercise_analyzer.py | ||
| tests/test_exercise_analyzer_cache.py | ||
| tests/test_json_robustness.py | ||
| tests/test_markdown_parser.py |
💡 What:
get_all_exercises(evolutia/material_extractor.py), replaced thesolution_lookup), carefully preserving the original 'first match' fallback logic.extract_by_topic(evolutia/material_extractor.py), hoistedtopic.lower()outside of the filesystem iteration loops to avoid redundant string allocations.extract_from_filewhere anF821 Undefined name 'result'linting error prevented caching on successful extraction.tryblock caching (cache_entry->_).🎯 Why:
.lower()redundantly inside.globandforloops across file trees incurs unnecessary overhead.📊 Impact:
🔬 Measurement:
python -m pytest tests/test_exercise_analyzer_cache.pyorpython -m pytest tests/to confirm that baseline behavior remains identical.PR created automatically by Jules for task 4314469170521182925 started by @glacy