Skip to content

⚡ Bolt: [performance improvement] Optimize pandas iteration and cache FAQ loading#564

Open
alinelena wants to merge 2 commits into
mainfrom
bolt-performance-improvements-14934560429555836660
Open

⚡ Bolt: [performance improvement] Optimize pandas iteration and cache FAQ loading#564
alinelena wants to merge 2 commits into
mainfrom
bolt-performance-improvements-14934560429555836660

Conversation

@alinelena
Copy link
Copy Markdown
Collaborator

💡 What:

  1. Replaced iterrows() with itertuples(index=False, name=None) in calc_solvMPCONF196.py and calc_MPCONF196.py.
  2. Replaced iterrows() with to_dict('records') in gscdb138.py and calc_elasticity.py.
  3. Extracted and cached yaml.safe_load for faqs.yml in build_components.py using @lru_cache(maxsize=1) and deepcopy().

🎯 Why:

  1. iterrows() is a known performance bottleneck in Pandas as it boxes every row into a Series. itertuples() and to_dict('records') provide a 10x-100x speedup for row iteration.
  2. yaml.safe_load is 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:

  • Iteration over large DataFrames in these critical calculation scripts is now significantly faster.
  • Rendering the FAQ component in the Dash application no longer incurs the expensive YAML parsing penalty.

🔬 Measurement:
Verified correctness with:

  • Isolated script runs uv run pytest ml_peg/calcs/...
  • Full test suite PYTHONPATH=. pytest tests/
  • uv run ruff check passed with no issues.
    Removed stray binary artifacts generated during testing before committing.

PR created automatically by Jules for task 14934560429555836660 started by @alinelena

- 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>
@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.

- 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>
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.

1 participant