Skip to content

Cache dashboard header to cut menu-change re-renders#11

Merged
MCamner merged 2 commits into
mainfrom
perf/dashboard-header-cache
Jun 21, 2026
Merged

Cache dashboard header to cut menu-change re-renders#11
MCamner merged 2 commits into
mainfrom
perf/dashboard-header-cache

Conversation

@MCamner

@MCamner MCamner commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Problem

print_header re-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 on title|subtitle|cwd:

  • Rapid transitions within MQ_DASHBOARD_CACHE_TTL (default 5s) reuse the last render.
  • Ticks past the TTL still refresh, so git/battery state never goes stale for long.
  • mq_dashboard_cache_invalidate lets state-mutating flows force a recompute.
  • MQ_DASHBOARD_CACHE_TTL=0 disables caching (test determinism).
  • cwd in 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_invalidate is available to wire into git/release Back later for zero staleness there.

Verification

  • New tests/dashboard-header-cache-smoke.sh: TTL hit, invalidation, cwd-miss, TTL=0 — all PASS.
  • Wired into test-all.sh; full selftest green; shell lint 107 → 108 files.

🤖 Generated with Claude Code

MCamner and others added 2 commits June 21, 2026 03:31
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>
@MCamner MCamner merged commit 1cf2d50 into main Jun 21, 2026
1 check passed
@MCamner MCamner deleted the perf/dashboard-header-cache branch June 21, 2026 01: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.

1 participant