Skip to content

perf(tui): render-signature redraw gate + concurrent VLAN detail - #86

Merged
lance0 merged 2 commits into
masterfrom
perf/tui-render-gate-vlan-fanout
Jun 25, 2026
Merged

lance0 merged 2 commits into
masterfrom
perf/tui-render-gate-vlan-fanout

Conversation

@lance0

@lance0 lance0 commented Jun 25, 2026 •

Copy link
Copy Markdown
Owner

What

Two independent perf wins from the ROADMAP perf-candidates list, verified together.

1. TUI render-signature redraw gate

The event loop drew on every iteration — and the always-on 180ms PreviewTick (~5.5 Hz) meant a full render_home_list rebuild (Vec<Row> clone + format!) even when nothing visible changed. The loop now skips terminal.draw when a conservative render signature is unchanged.

  • App::render_digest((w,h)) hashes everything the renderer can put on screen plus the terminal size. Over-inclusion is deliberate: an extra redraw is harmless, while omitting a visible field would freeze stale pixels. The two hashed collections (nav_counts, prefix-tree collapsed set) are sorted first for a stable digest.
  • RenderGate in app.rs stores the last drawn signature; draw_if_dirty is generic over B: Backend so tests drive it with TestBackend. record_drawn runs post-draw, so the stored signature matches an actually-clamped frame.
  • No render loop: ui::render mutates only viewports + idempotent clamps (x.min(bound)), so it settles in one frame and never oscillates.
  • No secret leak: masked input fields hash their rendered bullets (rendered_text()), never the raw token; cursor_pos() is hashed so arrow-key moves still redraw. Config/Filter modals feed the digest through their own hash_render_state.
  • Signature = "can pixels change", not "did state change": status_ttl is not hashed. It counts a transient status down but is never rendered, so hashing it would redraw every tick of the ~1.8s status window with no visible change. The expiry redraw still fires — clearing the TTL empties self.status, which is hashed. (If a future UI shows a TTL-derived value — countdown/fade — hash that derived visible value instead.)

The tick still drives debounce, status expiry, and the spinner — those paths still redraw. 8 TestBackend tests cover: idle-skip, spinner-while-loading-then-settle, transient-status (intermediate ticks don't redraw, status stays visible, expiry redraws once to clear), debounce-emits-command-no-redraw, async-result, keypress, resize, initial draw.

2. VLAN detail fan-out

vlan_prefixes and the VLAN group's scope are independent, so they now run under tokio::try_join! across all three paths (shared vlan_view_by_ref, TUI load_detail by-id, load_detail_by_ref by-ref) — one fewer round trip when a VLAN has both, same view shape. Mirrors the prefix-detail fix. The MCP vlan test now mocks the vlan-groups/{id}/ follow-up and asserts group_scope/group_scope_type, pinning that the concurrency doesn't drop the enrichment.

Verification

  • Gate (local): fmt clean; clippy --all-targets clean on --all-features and --no-default-features; 1134 all-features / 1039 no-default tests pass, 0 failed.
  • VlanView::build(...) is unchanged → VLAN output is byte-identical; the gate only changes when the existing render runs, not what it produces.

lance0 added 2 commits June 25, 2026 09:46
Render gate: the 180ms preview tick still drives debounce, status expiry, and
the loading spinner, but the event loop now skips `terminal.draw` when a
conservative render signature is unchanged — so idle ticks no longer rebuild
the Results table (the per-tick `Vec<Row>` clone + `format!`). The signature
(`App::render_digest`) hashes everything the renderer can put on screen plus
the terminal size; over-inclusion is deliberate (an extra redraw is harmless,
while omitting a visible field would freeze stale pixels). Masked input fields
hash their rendered bullets, never the raw token. `record_drawn` runs post-draw
so the stored signature matches an actually-clamped frame, and `ui::render`'s
only mutations are viewports + idempotent clamps, so it settles in one frame and
never oscillates. The two hashed collections (`nav_counts`, prefix-tree
collapsed set) are sorted first for a stable digest. 8 tests over `TestBackend`
cover the tick paths: idle-skip, spinner-while-loading-then-settle,
status-TTL-countdown, debounce-emits-no-redraw, async-result, keypress, resize,
and initial draw.

VLAN detail fan-out: `vlan_prefixes` and the VLAN group's scope are independent,
so fetch them with `try_join!` across all three paths (the shared
`vlan_view_by_ref`, TUI `load_detail` by-id, and `load_detail_by_ref` by-ref) —
saving a round trip when a VLAN has both, with the same view shape. The MCP vlan
test now mocks the `vlan-groups/{id}/` follow-up and asserts
`group_scope`/`group_scope_type`, so the concurrency can't silently drop the
enrichment.
status_ttl counts a transient status down but is never rendered, so hashing it
forced a full redraw on every tick of the ~1.8s status window with no visible
change. Drop it from render_digest — the expiry redraw still fires, since
clearing the TTL empties self.status, which is hashed. This tightens the gate to
its stated contract: redraw only when on-screen pixels can change.

Flip render_gate_transient_status_draws_until_it_clears so intermediate ticks
assert no redraw (and that the status stays visible on the last drawn frame),
while the expiry tick still asserts one redraw to clear. If a future UI shows a
TTL-derived value (countdown/fade), hash that derived visible value instead.
@lance0
lance0 merged commit fcd2735 into master Jun 25, 2026
4 checks passed
@lance0
lance0 deleted the perf/tui-render-gate-vlan-fanout branch June 25, 2026 14:05
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