Skip to content

feat(tui): incremental rendering for expand/collapse and scroll#1424

Merged
SorraTheOrc merged 2 commits intomainfrom
copilot/wl-0mnal79k20048stx-prototype-incremental-renderin
Apr 7, 2026
Merged

feat(tui): incremental rendering for expand/collapse and scroll#1424
SorraTheOrc merged 2 commits intomainfrom
copilot/wl-0mnal79k20048stx-prototype-incremental-renderin

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 7, 2026

The TUI rebuilds the entire visible-node tree on every expand/collapse and scroll event, causing measurable lag and occasional full event-loop lockups.

Core: visible-node cache (src/tui/state.ts)

  • Added cachedVisibleNodes: VisibleNode[] | null to TuiState
  • rebuildTreeState() invalidates the cache; buildVisibleNodes() populates it after a full traversal
  • incrementalExpand(state, nodeIdx) — splices only the newly-visible subtree into the cache (O(subtree) instead of O(total))
  • incrementalCollapse(state, nodeIdx) — removes the descendant block from the cache by index scan, no traversal needed
  • Both functions fall back to a full buildVisibleNodes() when the cache is stale
// expand: only the child subtree is computed and spliced in
const newVisible = cached.slice(0, nodeIdx + 1).concat(subtree, cached.slice(nodeIdx + 1));
state.cachedVisibleNodes = newVisible;

Controller wiring (src/tui/controller.ts)

  • buildVisible() changed to state.cachedVisibleNodes ?? buildVisibleNodes(state) — scroll and navigation are now O(1) lookups
  • KEY_TOGGLE_EXPAND, KEY_NAV_RIGHT, KEY_NAV_LEFT handlers use the incremental functions instead of mutating state.expanded directly and triggering a full rebuild
  • updateListSelection (scroll/navigate handler) now emits scroll perf events into perfMetrics when --perf is enabled

Tests (tests/tui/incremental-rendering.test.ts)

  • Unit tests for incrementalExpand / incrementalCollapse covering: no-children guard, already-expanded guard, stale-cache fallback, multi-level nesting, depth-based descendant removal
  • Cache invalidation regression tests
  • 30-item benchmark (10 roots × 2 children): asserts median expand/collapse latency < 200 ms
  • Smoke test verifying visible-node count consistency through full expand/collapse round-trips

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh gh issue create --repo TheWizardsCode/ContextHub --title Sample --body-file - (http block)
    • Triggering command: /usr/bin/gh gh issue create --repo TheWizardsCode/ContextHub --title Sample --body-file - les s s i/mo�� commit rktree-xia8cN/wt-q i/mock-bin/bash po/.worklog/tmp-bash -q nfig/composer/vecommit git (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 7, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Prototype incremental rendering to reduce TUI latency feat(tui): incremental rendering for expand/collapse and scroll Apr 7, 2026
Copilot AI requested a review from SorraTheOrc April 7, 2026 20:42
@SorraTheOrc SorraTheOrc marked this pull request as ready for review April 7, 2026 23:24
@SorraTheOrc SorraTheOrc merged commit 361fcd2 into main Apr 7, 2026
4 checks passed
@SorraTheOrc SorraTheOrc deleted the copilot/wl-0mnal79k20048stx-prototype-incremental-renderin branch April 28, 2026 18:09
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.

Prototype incremental rendering

2 participants