Memory saving in history arrays#4061
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a memory-optimized representation for dense per-minute historical series by adding an array.array('d')-backed wrapper, and begins returning it from history-loading helpers to reduce runtime memory pressure in Predbat’s minute-indexed histories.
Changes:
- Added
MinuteArray(dense, array-backed) as a drop-in replacement fordict[int, float]minute histories inutils.py. - Updated
fetch.pyto optionally returnMinuteArrayfor import/export and load minute histories. - Hardened
yesterday_reconstruct_car_slotsagainst mismatched car/octlots list lengths to avoid index errors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/predbat/utils.py | Adds the MinuteArray dense container to reduce memory usage of minute-indexed histories. |
| apps/predbat/fetch.py | Returns MinuteArray for certain minute-history loaders to reduce memory footprint. |
| apps/predbat/output.py | Adds an additional bound in the car-slot reload loop to prevent out-of-range indexing. |
Comment on lines
+28
to
+36
| class MinuteArray: | ||
| """Dense array-backed replacement for dict[int, float] keyed by contiguous minute indices. | ||
|
|
||
| Stores values in a stdlib array.array('d') to reduce memory ~29x versus a Python dict | ||
| (8 bytes per entry instead of ~232 bytes). Exposes the same get/[] interface used by | ||
| get_from_incrementing and get_now_from_cumulative so no callers need updating. | ||
|
|
||
| Only suitable when the key range is contiguous from 0 to size-1 (i.e. after smoothing). | ||
| """ |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.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.
No description provided.