Skip to content

Memory saving in history arrays#4061

Merged
springfall2008 merged 6 commits into
mainfrom
fix/save_ram
Jun 14, 2026
Merged

Memory saving in history arrays#4061
springfall2008 merged 6 commits into
mainfrom
fix/save_ram

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings June 14, 2026 18:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 for dict[int, float] minute histories in utils.py.
  • Updated fetch.py to optionally return MinuteArray for import/export and load minute histories.
  • Hardened yesterday_reconstruct_car_slots against 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 thread apps/predbat/fetch.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread apps/predbat/fetch.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread apps/predbat/utils.py
Comment thread apps/predbat/utils.py Outdated
Comment thread apps/predbat/utils.py
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).
"""
springfall2008 and others added 3 commits June 14, 2026 20:42
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@springfall2008 springfall2008 merged commit e73c506 into main Jun 14, 2026
1 check passed
@springfall2008 springfall2008 deleted the fix/save_ram branch June 14, 2026 19:51
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.

2 participants