Cache dashboard header to cut menu-change re-renders#11
Merged
Conversation
print_header re-forked the dashboard subprocess (pmset + ~6 git calls) on every menu loop tick, so returning from a sub-menu (Back) or re-rendering after invalid input paid the full cost each time. Add a TTL cache (MQ_DASHBOARD_CACHE_TTL, default 5s) keyed on title/subtitle/cwd. Rapid transitions reuse the last render; genuine ticks past the TTL still refresh. mq_dashboard_cache_invalidate lets state-mutating flows force a recompute. TTL=0 disables caching. Measured: 5 renders drop from ~1.41s to ~0.30s (~4.7x). New dashboard-header-cache smoke test wired into test-all. Co-Authored-By: Claude Opus 4.8 <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.
Problem
print_headerre-forked the dashboard subprocess (pmset+ ~6 git calls) on every menu loop tick. Returning from a sub-menu (Back) or re-rendering after invalid input paid the full cost each time — the open follow-up from #10.Fix
TTL cache in a new
print_dashboard_header(ui/terminal-ui/mq-ui.sh), keyed ontitle|subtitle|cwd:MQ_DASHBOARD_CACHE_TTL(default 5s) reuse the last render.mq_dashboard_cache_invalidatelets state-mutating flows force a recompute.MQ_DASHBOARD_CACHE_TTL=0disables caching (test determinism).cwdin the key → switching repos correctly misses the cache (git status is cwd-dependent).Measured
5 renders drop from ~1.41s to ~0.30s (~4.7x; ~280 ms saved per Back / menu change).
Tradeoff
Cache reuses for up to 5s, so a commit-then-Back can show stale
Dirty (N)in the header for ≤5s before it self-heals.mq_dashboard_cache_invalidateis available to wire into git/release Back later for zero staleness there.Verification
tests/dashboard-header-cache-smoke.sh: TTL hit, invalidation, cwd-miss, TTL=0 — all PASS.test-all.sh; full selftest green; shell lint 107 → 108 files.🤖 Generated with Claude Code