Skip to content

perf(tui): skip snapshot+draw when idle (LAN-1222 experiment) - #129

Merged
lance0 merged 3 commits into
masterfrom
lancey3/lan-1222-dirty-skip
Aug 24, 2026
Merged

lance0 merged 3 commits into
masterfrom
lancey3/lan-1222-dirty-skip

Conversation

@lance0

@lance0 lance0 commented Aug 23, 2026 •

Copy link
Copy Markdown
Owner

Skip snapshot_for_render() + terminal.draw on ticks where nothing changed (LAN-1222).

What changes

  • Session::render_generation is bumped by the SessionLock write guard on release, so every mutation path — hop stats, enrichment, PMTUD, pause/reset — marks the TUI dirty. A writer that bypasses the lock is a compile error, not a stale frame.
  • After the pre-draw polls, the loop builds a RenderFingerprint (session generation, overlays, theme, status, update banner, replay clock, settings, target input, IX cache status, target-list rows) and skips the snapshot and draw when it matches the last frame.
  • Tick stays 16ms; a playing replay stays dirty via replay_current_ms. A terminal resize invalidates the last fingerprint so the next tick redraws.

Measured — docker, ttl 1.1.1.1, 9 hops, 60s, both binaries in the same network window:

CPU over 60s avg of one core
master 0.86s 1.43%
this PR 0.22s 0.37%

Not covered

  • format_cache_age in the settings modal reads the wall clock at render time, so its "Xm ago" text only refreshes when something else on screen changes.

@lance0

lance0 commented Aug 23, 2026

Copy link
Copy Markdown
Owner Author

Follow-up on the idle-skip review: redraw is no longer keyed only on session generation plus static input chrome.

The loop now builds a RenderFingerprint after the pre-draw polls (clear_old_status, add-target, update check, IX get_cache_status, target-list cache refresh). That includes status text, update banner, IX fetched_at/expired/refreshing, and the actual target-list rows (so a 30-tick refresh of another session’s hops/loss dirties even when the current hop generation is unchanged). Playing replay still dirties via the clock.

Tests cover status expiry, add-target poll, update-check recv, open target-list refresh, and IX fetched_at. Commit d8338ba.

@lance0
lance0 force-pushed the lancey3/lan-1222-dirty-skip branch from d8338ba to 785438f Compare August 23, 2026 19:34
lance0 added 2 commits August 24, 2026 11:18
LAN-1222 experiment: bump Session::render_generation on hop_mut/reset
and skip snapshot_for_render + terminal.draw when a post-poll
RenderFingerprint matches the last frame. Tick rate stays 16ms.
Playing replay stays dirty via the progress clock.

Clippy 1.98 nits stay on chore/clippy-1.98-nits, not this branch.
The dirty-skip fingerprint relied on hop_mut()/reset_stats() to bump
render_generation, but enrichment (rdns/asn/geo/ix), the PMTUD driver,
and total_sent all mutate the session under state.write() without going
through hop_mut, so their changes stayed off-screen until the next probe
bumped the counter — for the whole duration of a pause.

Wrap the session lock in SessionLock, whose write guard bumps
render_generation on release. Every mutation path now marks the TUI
dirty, and a writer that forgets is a compile error rather than a stale
frame. The manual bumps in hop_mut/reset_stats become redundant.
@lance0
lance0 force-pushed the lancey3/lan-1222-dirty-skip branch from 785438f to 151d9e1 Compare August 24, 2026 15:27
Resize events were dropped by the Key-only input match, and the frame
skip means terminal.draw's autoresize no longer runs every tick, so a
resize while nothing else changed left the old layout on screen until
the next dirty frame — up to 2s (the rate-limit worker's tick) when
paused or in a finished replay. Treat a Resize event as invalidating
the last fingerprint so the next tick redraws.
@lance0
lance0 force-pushed the lancey3/lan-1222-dirty-skip branch from 70bdf6d to 3eebf8f Compare August 24, 2026 15:42
@lance0
lance0 marked this pull request as ready for review August 24, 2026 15:49
@lance0
lance0 merged commit 06994ae into master Aug 24, 2026
5 checks passed
@lance0
lance0 deleted the lancey3/lan-1222-dirty-skip branch August 24, 2026 15:49
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