Repository navigation
Performance Optimization for Large Grids (Vectorization & Caching) - #66
Merged
Merged
Conversation
…ation caching, and SVG boosting refinements. Documented NAD optimization investigations (Strategies 1 & 3).
…fields and restore name_to_idx. All 235 tests passing.
…ensure instant availability on mount.
…validation, and performance budget tests
marota
pushed a commit
that referenced
this pull request
Apr 30, 2026
Reconciliation of section 2 (0.5.0): - Drop misattributed PRs that were actually pre-rebrand: save/reload (#49/#52), MW Start (#62), interaction-logging (#64), SLD highlights (#63), load shedding initial integration (#61). All now properly cited in section 1.5–1.6. - Disambiguate App.tsx refactor history: PR #56 (hooks, 2100 → 800, pre-rebrand) vs PR #74 (components, 1000 → 650, 0.5.0) vs PR #75 (memoization Phase 2, same LoC). - Add accurate 0.5.0 PRs: #66 (vectorization w/ benchmark table), #69/#70/#71 (UI polish), #72 (curtailment), #73 (loads_p/gens_p format + configurable MW), #74/#75 (App.tsx decomposition), #78 (PST tap re-simulation), #84/#86/#87/#90 (detachable tabs). - Add a recap table summarizing what's truly new in 0.5.0. Diagrams added (Mermaid, GitHub-rendered): - Gantt timeline of all 4 phases (top of doc). - High-level architecture (frontend / backend / data). - Two-step analysis sequence diagram (section 1.6). - App.tsx LoC evolution flow (section 2.4). - Backend mixin decomposition before/after PR #104/#106 (section 3). - PyPSA-EUR pipeline flowchart (section 4). https://claude.ai/code/session_01Pg7fuCUG2edfm5PyHS6SbN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: Performance Optimization for Large Grids (Vectorization & Caching)
Summary
This PR implements critical backend performance optimizations for ExpertAssist, focusing on the observation and simulation pipeline. For large grids (e.g., France 10k+ branches), these changes provide a 4x speedup in manual action simulation latency.
Key Changes
1. Vectorized Simulation Pipeline (RecommenderService)
Replaced high-overhead Python loops with NumPy vectorized operations in several key areas:
care_mask& Overload Detection: Achieved a 1,100x speedup (12.17s -> 0.01s) by eliminating per-branch attribute lookups and rho-balancing loops._get_network_flows): Optimized result extraction frompypowsyblnetworks, resulting in a 13x speedup._compute_deltas): Vectorized the terminal-aware delta logic, providing a 47x speedup.2. Observation Caching
Implemented an internal cache for
get_obs()results during the manual action simulation loop. This eliminates redundant data retrieval and property access overhead, improving the simulation body latency by another ~600ms.3. SVG Boosting (Frontend)
Maintained and refined the "Phase 1" SVG boosting utility in
standalone_interface.html. This ensures that labels, nodes, and flow arrows remain legible on large grids by dynamically scaling them based on the diagram's native resolution.Optimization Investigations (NAD Reduction)
As part of this work, we extensively investigated dynamic SVG reduction strategies:
Detailed findings on these investigations are documented in
docs/nad_optimization.md.Performance Benchmarks
Verification
Verification was performed using
scripts/profile_diagram_perf.py, which measures backend latency across N, N-1, and Manual Action scenarios on the full French grid.Test Consolidation & Performance Verification
The performance optimization logic is now fully covered by a consolidated and expanded test suite.
EOF