Skip to content

perf: use Polars streaming engine for LP file writing#563

Closed
FBumann wants to merge 2 commits intoPyPSA:masterfrom
FBumann:perf/polars-streaming
Closed

perf: use Polars streaming engine for LP file writing#563
FBumann wants to merge 2 commits intoPyPSA:masterfrom
FBumann:perf/polars-streaming

Conversation

@FBumann
Copy link
Copy Markdown
Collaborator

@FBumann FBumann commented Jan 31, 2026

Summary

  • Extract _format_and_write() helper that uses lazy().collect(engine="streaming") with automatic fallback to eager evaluation
  • Replaces 7 repeated instances of df.select(concat_str(...)).write_csv(...) with a single reusable function
  • The Polars streaming engine can significantly reduce memory usage and improve throughput for large LP files

Benchmarks (vs master)

Benchmark master This PR Speedup
basic N=500 (500K vars) 940ms 704ms 1.3x
basic N=1000 (2M vars) 3451ms 2830ms 1.2x
knapsack 100K 70ms 57ms 1.2x
PyPSA 24 snapshots (60K vars) 484ms 438ms 1.1x
PyPSA 100 snapshots (249K vars) 1141ms 1278ms ~1.0x
PyPSA 500 snapshots (1.2M vars) 5761ms 4428ms 1.3x

@FBumann FBumann marked this pull request as draft January 31, 2026 20:03
Extract _format_and_write() helper that uses lazy().collect(engine="streaming")
with automatic fallback, replacing 7 instances of df.select(concat_str(...)).write_csv(...).
@FBumann FBumann force-pushed the perf/polars-streaming branch from 1c003d1 to 86232e8 Compare January 31, 2026 20:07
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@FBumann
Copy link
Copy Markdown
Collaborator Author

FBumann commented Jan 31, 2026

Combining into a single PR with all perf improvements.

@FBumann FBumann closed this Jan 31, 2026
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