Repository navigation
Read a few points of an output with far less memory and time - #6
Merged
Merged
Conversation
read_output read a few points through a filtered dataset scan, which found the right row groups but buffered some 200 MB more than the rows it returned. It now finds each point's row group from the row groups' statistics and reads those directly; a file without one row group per point still goes through the filter. mix_output checked the set's members against every row of the output, which pandas does slowly for string columns: 2.5 s for a few points of PyPSA-Eur's generation. It now checks them against the distinct keys. On the PyPSA-Eur set, a generation plot's peak memory falls from about 615 MB to 336 MB and its time from about 6 s to 1 s, which matters on the 512 MB instance the server runs on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
The deployed backend runs on a 512 MB instance. With the PyPSA-Eur set it uses about 450 MB while idle and reached 497 MB after a single generation plot. A generation plot also took about 10 s. This PR fixes both causes. Results don't change.
Changes
mga_format.read_output: to read a few points, it used a filtered dataset scan (pq.read_table(..., filters=...)). The scan found the right row groups but buffered about 200 MB more than the rows it returned. It now looks up each point's row group from the row-group statistics (the format requires one row group per point) and reads them withParquetFile.read_row_groups. A file without one row group per point still goes through the filter.validate_outputshares the lookup.mix_output: it checked the set's members against every row of the output (isinover 420,000 Arrow strings): 2.5 s for a few points of generation. It now checks against the distinct keys.Measured on the PyPSA-Eur set (local Docker backend)
mix_output, first call, includes the readplot_data("generation")Testing
mga-formatandmga-compasstests pass (162), and so do the backend's (45).Merging redeploys the backend on Koyeb.
🤖 Generated with Claude Code