perf(storage): debounce saves via async_delay_save (PERF-3)#614
Merged
Conversation
A single TaskMate operation frequently calls async_save 2-4x (mutate record, award points, refresh), each serialising the whole _data blob to disk. Route async_save through Store.async_delay_save so those collapse into one debounced write (1s window). HA flushes pending delayed saves on shutdown; async_shutdown also forces a flush. - storage: async_save -> async_delay_save(lambda: _data, 1.0s); new async_save_now() for immediate writes; version still bumps per logical save (keeps PERF-2 cache invalidation correct) - coordinator.async_shutdown: await storage.async_save_now() so an entry unload/reload can't drop the last mutation - tests/conftest FakeStore: async_delay_save writes through immediately for deterministic test persistence Tests: test_save_debounce.py (delay-save used, no direct write; save_now writes through; per-save version bump; shutdown flush). Storage/integration/backup suites green; live-verified on ha-dev: add_points +5 survived a full HA restart (debounced write landed), then reverted.
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.
PERF-3 — Debounce storage saves
A single TaskMate operation frequently calls
async_save2-4× (mutate a record → award points → refresh), each serialising the entire_datablob to disk.Fix
Route
async_savethroughStore.async_delay_save(lambda: _data, 1.0s), which coalesces rapid saves into one debounced disk write. The 1 s window fully absorbs the within-operation duplicates while keeping any crash-loss window tiny.async_savenow debounced; newasync_save_now()for immediate writes; thedata_versionbump still happens per logical save, so PERF-2 cache invalidation stays correct.async_shutdowncallsawait storage.async_save_now()so an entry unload/reload flushes any pending write (HA already flushes delayed saves on full shutdown; this covers reloads too).FakeStore.async_delay_savewrites through immediately for deterministic test persistence.Verification
test_save_debounce.py:async_saveusesasync_delay_save(no direct write) and bumps version each call;async_save_nowwrites through;async_shutdownflushes.TestOneShotChoresfailures in mixed runs are the documented pre-existing order-pollution — they fail identically on the unchanged tree and pass in isolation.)add_points +5→ waited out the debounce → full HA restart → balance persisted (63), proving the delayed write lands; reverted.Part of the v4.3.1 audit fix campaign. No version bump / release.