Skip to content

Memory usage and debug read fixes#4025

Merged
springfall2008 merged 5 commits into
mainfrom
fix/debug_read
Jun 7, 2026
Merged

Memory usage and debug read fixes#4025
springfall2008 merged 5 commits into
mainfrom
fix/debug_read

Conversation

@springfall2008
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings June 7, 2026 22:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 targets two operational concerns in Predbat: reducing memory pressure from SoC→rate curve caching, and improving robustness when loading older debug YAML snapshots.

Changes:

  • Reduced cache-key churn in charge/discharge rate curve lookups by rounding SoC inputs (intended to improve cache hit-rate and memory usage).
  • Optimised rate_min_forward_calc() from an O(n²) slice-min approach to an O(n) right-to-left running-min scan.
  • Added backwards-compatible handling for old-format octopus_slots in debug YAML, plus a new unit test for rate_min_forward_calc().

Reviewed changes

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

Show a summary per file
File Description
coverage/cases/predbat_debug_agile1.yaml.expected.json Updates expected outputs to match small numeric differences from the SoC rounding change.
apps/predbat/utils.py Rounds SoC before cached curve evaluation to reduce cache key cardinality (memory/perf).
apps/predbat/userinterface.py Adds migration logic for old debug YAML octopus_slots format.
apps/predbat/unit_test.py Registers a new test module in the unit test runner.
apps/predbat/tests/test_rate_min_forward_calc.py Adds coverage for rate_min_forward_calc() behavior and edge cases.
apps/predbat/fetch.py Replaces O(n²) forward-min computation with an O(n) running-min implementation.

Comment thread apps/predbat/userinterface.py
Comment thread apps/predbat/utils.py
Comment on lines 996 to +1000
def get_charge_rate_curve(soc, charge_rate_setting, soc_max, battery_rate_max_charge, battery_charge_power_curve, battery_rate_min, battery_temperature, battery_temperature_curve):
"""
Compute true charging rate from SoC and charge rate setting
"""
return get_charge_rate_curve_cached(soc, charge_rate_setting, soc_max, battery_rate_max_charge, charge_curve_to_tuple(battery_charge_power_curve), battery_rate_min, battery_temperature, charge_curve_to_tuple(battery_temperature_curve))
return get_charge_rate_curve_cached(round(soc, 1), charge_rate_setting, soc_max, battery_rate_max_charge, charge_curve_to_tuple(battery_charge_power_curve), battery_rate_min, battery_temperature, charge_curve_to_tuple(battery_temperature_curve))
Comment thread apps/predbat/utils.py Outdated
@springfall2008 springfall2008 merged commit 5143ba4 into main Jun 7, 2026
1 check passed
@springfall2008 springfall2008 deleted the fix/debug_read branch June 7, 2026 22:22
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