⚡ Bolt: [performance improvement] Optimize pandas iteration and cache FAQ loading#564
⚡ Bolt: [performance improvement] Optimize pandas iteration and cache FAQ loading#564alinelena wants to merge 2 commits into
Conversation
- Replaced slow `iterrows()` with `itertuples()` and `to_dict('records')` across the codebase.
- Cached `yaml.safe_load` for `faqs.yml` using `lru_cache` and `deepcopy`.
Co-authored-by: alinelena <3306823+alinelena@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. |
- Replaced slow `iterrows()` with `itertuples()` and `to_dict('records')` across the codebase.
- Cached `yaml.safe_load` for `faqs.yml` using `lru_cache` and `deepcopy`.
Co-authored-by: alinelena <3306823+alinelena@users.noreply.github.com>
💡 What:
iterrows()withitertuples(index=False, name=None)incalc_solvMPCONF196.pyandcalc_MPCONF196.py.iterrows()withto_dict('records')ingscdb138.pyandcalc_elasticity.py.yaml.safe_loadforfaqs.ymlinbuild_components.pyusing@lru_cache(maxsize=1)anddeepcopy().🎯 Why:
iterrows()is a known performance bottleneck in Pandas as it boxes every row into a Series.itertuples()andto_dict('records')provide a 10x-100x speedup for row iteration.yaml.safe_loadis extremely slow compared to native Python parsing. Repeatedly parsing the same static configuration file (faqs.yml) on every component render adds unnecessary overhead. Caching it eliminates this bottleneck.📊 Impact:
🔬 Measurement:
Verified correctness with:
uv run pytest ml_peg/calcs/...PYTHONPATH=. pytest tests/uv run ruff checkpassed with no issues.Removed stray binary artifacts generated during testing before committing.
PR created automatically by Jules for task 14934560429555836660 started by @alinelena