Skip to content

perf(tui,gpu): draw Rio content before the first poll and spawn the child earlier - #82

Merged
piny4man merged 1 commit into
mainfrom
perf/rio-first-draw
Oct 17, 2026
Merged

piny4man merged 1 commit into
mainfrom
perf/rio-first-draw

Conversation

@piny4man

Copy link
Copy Markdown
Owner

NUKE-113. A Rio open showed an empty panel for about 30 ms. The parent spawned the PTY child only after the whole GL setup, and the child then waited up to 16 ms in poll_batch before its first draw.

Changes

  • Draw first: tui_loop (src/main.rs) draws the first frame before the first input wait. It's a testable loop with draw and poll closures.
  • Spawn earlier: GlState::new is split.
    • GlState::open_window creates the window and picks the GL config.
    • resumed then joins the fonts, computes the grid and spawns the Rio child.
    • GlState::new then builds the context, surface and renderer while the child starts up.
  • Blank frame kept: it's drawn at alpha 0, and the fade-in (fade_step) starts on the first frame with glyphs. In practice the child now finishes drawing before GL setup does, so the first present already has content.
  • Resize fix: poll_batch dropped Event::Resize, so after a window resize the Rio grid re-laid out only after the next key. Resize now triggers a redraw. This was pre-existing on main; it was found during manual testing and fixed here on request.
  • Docs: docs/hotpath-findings.md marks finding 3 fixed and gains an "After NUKE-113" section. docs/hotpath-profiling.md lists the split phases.

Results

Interleaved A/B against main (dca12a7), 30 cold + 30 warm opens per cell. First-content p95, in ms:

Open Perf main → branch Balanced main → branch
cold Rio 74.0 → 40.6 79.9 → 45.7
warm Rio 77.6 → 44.4 86.8 → 53.1
cold native 37.7 → 37.3 42.5 → 42.4
warm native 46.3 → 43.7 47.8 → 47.7
  • Done-when: Rio is within 10 ms of native in all four cells, at +0.7 to +5.4 ms.
  • Rio's balanced-vs-performance ratio is now as noisy as native's, because both open in about 40 ms. NUKE-115 stays open; the doc explains why.

Validation

  • cargo fmt --check.
  • Clippy with -D warnings, default features and --all-features.
  • cargo test --all-targets with default, hotpath and hotpath-alloc features: 334 / 335 / 335 passed. New tests cover the draw-first loop, idle draws while effects run, the fade rule, and resize mapping.
  • Hotpath reports show GlState::open_window, GlState::new and Session::spawn.
  • Manual: Rio and native opened live. Typing, selection, fade-in and close behave as before, and Rio now follows a resize without typing. --measure exits normally.

…hild earlier

A Rio open showed an empty panel for ~30 ms. The parent spawned the PTY
child only after the whole GL setup, and the child then waited up to a
frame in poll_batch before its first draw.

The TUI loop now draws before it first waits for input. GlState::new is
split: open_window creates the window and picks the GL config, then
resumed joins the fonts, computes the grid and spawns the Rio child, and
GlState::new builds the context, surface and renderer while the child
starts. The blank first present stays at alpha 0, and the fade-in now
starts on the first frame with glyphs.

The child now redraws on terminal resize. poll_batch dropped
Event::Resize, so the Rio grid re-laid out only after the next key.

Interleaved A/B against main (n=30 per cell): Rio first-content p95
drops ~33 ms in both profiles (perf 74.0 -> 40.6 cold, balanced 79.9 ->
45.7) and is within 0.7-5.4 ms of native. Native is unchanged.
docs/hotpath-findings.md records the results.
@piny4man
piny4man merged commit c777c0a into main Oct 17, 2026
1 check passed
@piny4man
piny4man deleted the perf/rio-first-draw branch October 17, 2026 10:10
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