Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion docs/hotpath-findings.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ separately.

### 5. The probe folds no-op keys into the next change on Rio

**Fixed in [NUKE-114](https://linear.app/tiendacables/issue/NUKE-114); see
[After NUKE-114](#after-nuke-114--2026-10-17).**

7 of 254 Rio input samples are 110–643 ms, each about one pause between key
presses. A key that changes nothing on screen (e.g. `Up` on the first row,
`Backspace` on an empty query) produces no damage, so the pending sample is
Expand Down Expand Up @@ -356,6 +359,66 @@ What remains:
EGL config selection) is now the critical path for both frontends.
- No follow-up issue is proposed for Rio: the done-when target is met.

## After NUKE-114 — 2026-10-17

Branch `perf/probe-noop-keys` (on `c777c0a`, which includes NUKE-113). The
input probe now uses one rule for both frontends:

- Only a frame with a visible change answers an input. Rio already had this
through its damage gate. Native now compares each frame's cells with the
previous frame's (`LastFrame` in `src/gpu/window.rs`, only while
`HYPRBURST_PERF` is on), so a key that repaints the same picture no longer
closes a sample.
- A pending input expires when the next key arrives more than 50 ms later
(`INPUT_EXPIRY` in `src/perf.rs`). It is printed as
`query-input-unanswered` or `selection-input-unanswered` with its age, and
the new key starts its own sample. Keys within 50 ms still fold, so bursts
are measured from their first key.

The finding proposed dropping a sample "after one refresh with no damage".
That can't work on Rio: a no-op key makes the child send no PTY bytes, so the
parent gets no wake and no frame to time out on. The next key is the first
event that follows, so the rule is checked there.

One correction to finding 5: `Up` on the first row is not a no-op. Selection
wraps to the last row, so it changes the frame. `Backspace` on an empty query
and `Down` with a single result are true no-ops.

### Live sessions, performance (ms)

Typed manually, same script each time (query edits, `Backspace` on an empty
query, arrow keys, ~0.5–1 s pauses):

| Build | Frontend | Metric | n | median | p95 | max |
| --- | --- | --- | ---: | ---: | ---: | ---: |
| before (`c777c0a`) | rio | query | 13 | 0.70 | 759.96 | 759.96 |
| before | rio | selection | 18 | 0.77 | 0.94 | 0.94 |
| before | native | query | 12 | 0.27 | 0.79 | 0.79 |
| before | native | selection | 14 | 0.28 | 0.35 | 0.35 |
| after | rio | query | 46 | 0.73 | 1.00 | 1.33 |
| after | rio | selection | 42 | 0.71 | 0.79 | 0.86 |
| after | rio | query unanswered | 1 | 346.6 | — | — |
| after | native | query | 16 | 0.34 | 0.52 | 0.52 |
| after | native | selection | 32 | 0.34 | 0.47 | 0.48 |

Before, one Rio query sample read 760 ms: a no-op `Backspace` answered by the
next key's frame. After, no answered sample in either frontend exceeds
1.4 ms; the no-op shows up as an unanswered line instead.

A targeted round on the final build (`Backspace` ×3 on an empty query, `f`,
`Backspace`, ~1 s apart) gives the same result in both frontends: three
`query-input-unanswered` lines (0.4–1.5 s, one per no-op key) and two
answered samples (Rio 0.81–0.90 ms, native 0.32–0.36 ms).

**Done when met:** no Rio sample above ~20 ms comes from a no-op key, and
`docs/hotpath-profiling.md` describes the rule. Rio medians are unchanged;
native medians rise ~0.06 ms (0.27–0.28 → 0.34 ms), consistent with the
probe-only cell comparison, which normal runs don't pay.

Remaining limit: a no-op key followed by another key within 50 ms still
folds, so that sample can read up to ~50 ms. Real input latency here is
1–2 ms, so such a sample stands out.

## Follow-ups

Filed as sub-issues of NUKE-109:
Expand All @@ -365,5 +428,5 @@ Filed as sub-issues of NUKE-109:
| [NUKE-111](https://linear.app/tiendacables/issue/NUKE-111) Cache font resolution and skip the Nerd Font scan | 1 | — | fixed (see above) |
| [NUKE-112](https://linear.app/tiendacables/issue/NUKE-112) Load fonts while the window and GL context are created | 2 | NUKE-111 | fixed (see above) |
| [NUKE-113](https://linear.app/tiendacables/issue/NUKE-113) Rio: draw before the first input poll, spawn the child earlier | 3 | — | fixed (see above) |
| [NUKE-114](https://linear.app/tiendacables/issue/NUKE-114) Probe: count no-op keys the same way in both frontends | 5 | — | open |
| [NUKE-114](https://linear.app/tiendacables/issue/NUKE-114) Probe: count no-op keys the same way in both frontends | 5 | — | fixed (see above) |
| [NUKE-115](https://linear.app/tiendacables/issue/NUKE-115) Re-measure warm native open in balanced | 4 | NUKE-111, NUKE-112 | open: both frontends now open in ~40 ms, and the ≤ 10% ratio swings 1.5–20% between sessions |
22 changes: 15 additions & 7 deletions docs/hotpath-profiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,27 @@ stderr line per sample, `hyprburst-perf <metric> <frontend> <ms>`, where
| `first-content-present` | process start (`main`) | the first presented frame that draws any glyph |
| `query-input-to-present` | a typed character, `Backspace`, or `Tab` | the first presented frame with a visible change |
| `selection-input-to-present` | an arrow key or `PageUp`/`PageDown` | the first presented frame with a visible change |
| `query-input-unanswered` | a query key that changed nothing on screen | the next key, more than 50 ms later |
| `selection-input-unanswered` | a selection key that changed nothing on screen | the next key, more than 50 ms later |

The Rio window presents its first frame before the PTY child has drawn
anything, so for `rio` only `first-content-present` is when the launcher becomes
visible; for `native` the two coincide. With the probe on, `--measure` stays
open until content is presented.

Keys pressed before that frame are folded into the first one, so a burst is
measured from its first key. For the Rio frontend the change has to come back
from the child over the PTY, so this includes the child's filtering and
rendering, the PTY round trip, and the parent's VT parse and draw. A key that
changes nothing on screen (e.g. `Down` with one result) is answered by the next
visible change, so take the p95, not the max, as the figure of record. With the
probe unset, nothing is recorded.
Both frontends answer an input only with a frame whose cells differ from the
last one: Rio through its damage gate, native by comparing the frame's cells
with the previous frame's (only while the probe is on). Keys pressed within
50 ms of a pending input are folded into it, so a burst (key repeat, fast
typing) is measured from its first key. A key that comes later means the
pending one changed nothing on screen (e.g. `Backspace` on an empty query,
`Down` with one result): it is printed as `*-input-unanswered` with its age,
not timed to the next key's frame, and the new key starts its own sample. A
no-op key followed by another within 50 ms still folds, so such a sample can
read up to ~50 ms. For the Rio frontend the change has to come back from the
child over the PTY, so `*-input-to-present` includes the child's filtering
and rendering, the PTY round trip, and the parent's VT parse and draw. With
the probe unset, nothing is recorded.

`scripts/perf-summary.sh` turns one or more logs into n / median / p95 / max
per metric and frontend; other stderr lines are ignored.
Expand Down
105 changes: 93 additions & 12 deletions src/gpu/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ struct App {
perf: Option<InputProbe>,
/// `HYPRBURST_PERF` first-content probe; `None` when the probe is off.
open_probe: Option<OpenProbe>,
/// The last native frame, for the input probe; `None` when it is off.
last_frame: Option<LastFrame>,
}

impl App {
Expand Down Expand Up @@ -288,6 +290,7 @@ impl App {
render_cache: RenderCache::new(),
perf: perf::enabled().then(InputProbe::default),
open_probe: perf::enabled().then(OpenProbe::default),
last_frame: perf::enabled().then(LastFrame::default),
frontend,
gl: None,
cell: CellMetrics::new(1, 1),
Expand Down Expand Up @@ -439,11 +442,11 @@ impl ApplicationHandler<()> for App {
return;
};
if let Some(action) = key_to_action(&event) {
if let (Some(probe), Some(kind)) =
(&mut self.perf, InputKind::of_action(action))
{
probe.input(kind, Instant::now());
}
record_input(
&mut self.perf,
InputKind::of_action(action),
"native",
);
core.apply(action);
self.repaint_needed = true;
if !core.running() {
Expand All @@ -458,11 +461,7 @@ impl ApplicationHandler<()> for App {
..
} => {
if let Some(key) = terminal_key(&event) {
if let (Some(probe), Some(kind)) =
(&mut self.perf, key.input_kind())
{
probe.input(kind, Instant::now());
}
record_input(&mut self.perf, key.input_kind(), "rio");
session.send_key(key);
}
}
Expand Down Expand Up @@ -537,8 +536,9 @@ impl ApplicationHandler<()> for App {
return;
}

// Whether this frame shows new content (not just a fade step):
// only such a frame answers a pending input for the probe.
// Whether this frame shows new content (not just a fade step or
// a repaint of the same cells): only such a frame answers a
// pending input for the probe.
let mut visible_change = true;
match &mut self.frontend {
Frontend::Launcher(core) => {
Expand All @@ -554,6 +554,9 @@ impl ApplicationHandler<()> for App {
&mut self.bgs,
&mut self.glyphs,
);
if let Some(last) = &mut self.last_frame {
visible_change = last.changed(&self.bgs, &self.glyphs);
}
}
Frontend::Rio {
session: Some(session),
Expand Down Expand Up @@ -1341,10 +1344,88 @@ fn fade_step(fade_start: &mut Option<Instant>, has_content: bool, now: Instant)
(1.0 - (1.0 - t).powi(4), t < 1.0)
}

/// Record a key for the input probe, reporting the input it replaces if that
/// one changed nothing on screen.
fn record_input(probe: &mut Option<InputProbe>, kind: Option<InputKind>, frontend: &str) {
if let (Some(probe), Some(kind)) = (probe, kind)
&& let Some((unanswered, age)) = probe.input(kind, Instant::now())
{
perf::emit(unanswered.unanswered_metric(), frontend, age);
}
}

/// The last native frame's cells, so the `HYPRBURST_PERF` probe can tell a
/// visible change from a repaint of the same picture (a key that changed
/// nothing), as Rio's damage gate does.
#[derive(Debug, Default)]
struct LastFrame {
seen: bool,
bgs: Vec<BgCell>,
glyphs: Vec<CellInstance>,
}

impl LastFrame {
/// Whether this frame differs from the last one; a changed frame becomes
/// the new last one (reusing the buffers' capacity).
fn changed(&mut self, bgs: &[BgCell], glyphs: &[CellInstance]) -> bool {
let changed = !self.seen || self.bgs != bgs || self.glyphs != glyphs;
if changed {
self.seen = true;
self.bgs.clear();
self.bgs.extend_from_slice(bgs);
self.glyphs.clear();
self.glyphs.extend_from_slice(glyphs);
}
changed
}
}

#[cfg(test)]
mod tests {
use super::*;

fn glyph(col: u16, ch: char) -> CellInstance {
CellInstance {
col,
row: 0,
ch,
bold: false,
color: [1.0; 3],
}
}

fn bar(row: u16) -> BgCell {
BgCell {
col: 0,
row,
color: [0.2, 0.2, 0.2, 1.0],
}
}

#[test]
fn the_first_frame_counts_as_a_change() {
assert!(LastFrame::default().changed(&[], &[]));
}

#[test]
fn repainting_the_same_cells_is_not_a_change() {
let mut last = LastFrame::default();
let glyphs = [glyph(0, '>'), glyph(2, 'f')];
assert!(last.changed(&[bar(1)], &glyphs));
assert!(!last.changed(&[bar(1)], &glyphs));
}

#[test]
fn a_moved_selection_or_new_glyph_is_a_change() {
let mut last = LastFrame::default();
let glyphs = [glyph(0, '>'), glyph(2, 'f')];
last.changed(&[bar(1)], &glyphs);
assert!(last.changed(&[bar(2)], &glyphs));
assert!(last.changed(&[bar(2)], &[glyph(0, '>'), glyph(2, 'i')]));
assert!(last.changed(&[bar(2)], &[glyph(0, '>')]));
assert!(!last.changed(&[bar(2)], &[glyph(0, '>')]));
}

#[test]
fn fade_waits_for_content_without_animating() {
let mut start = None;
Expand Down
89 changes: 84 additions & 5 deletions src/perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ impl InputKind {
}
}

/// The metric name for an input that no visible change answered.
pub fn unanswered_metric(self) -> &'static str {
match self {
Self::Query => "query-input-unanswered",
Self::Selection => "selection-input-unanswered",
}
}

/// Classify a launcher action. Launching, cancelling, and mouse selection
/// close the window, so they have no presented frame to measure.
pub fn of_action(action: LauncherAction) -> Option<Self> {
Expand Down Expand Up @@ -74,20 +82,37 @@ pub fn emit(metric: &str, frontend: &str, elapsed: Duration) {
eprintln!("{}", line(metric, frontend, elapsed));
}

/// How long an input may go unanswered before the next input replaces it.
pub const INPUT_EXPIRY: Duration = Duration::from_millis(50);

/// Tracks the oldest input not yet shown on screen.
///
/// Keys that arrive before the next presented change are folded into the
/// first one, so a burst is measured from its first key — the latency the
/// user waits for.
/// Only a presented frame with a visible change answers an input. Keys that
/// arrive within [`INPUT_EXPIRY`] of the pending one are folded into it, so a
/// burst is measured from its first key — the latency the user waits for. A
/// key that comes later replaces a pending input instead: that input changed
/// nothing on screen, and is reported as unanswered rather than timed to the
/// next key's frame.
#[derive(Debug, Default)]
pub struct InputProbe {
pending: Option<(InputKind, Instant)>,
}

impl InputProbe {
/// Record an input at `at`.
pub fn input(&mut self, kind: InputKind, at: Instant) {
/// Record an input at `at`. A pending input older than [`INPUT_EXPIRY`]
/// changed nothing on screen (a no-op key); it is returned with its age
/// and this input starts a new sample, instead of being answered by this
/// input's frame.
pub fn input(&mut self, kind: InputKind, at: Instant) -> Option<(InputKind, Duration)> {
let expired = match self.pending {
Some((pending, since)) if at.saturating_duration_since(since) > INPUT_EXPIRY => {
self.pending = None;
Some((pending, at.saturating_duration_since(since)))
}
_ => None,
};
self.pending.get_or_insert((kind, at));
expired
}

/// A frame showing a visible change was presented at `at`: return the
Expand Down Expand Up @@ -193,4 +218,58 @@ mod tests {
// Consumed: a later frame with no new input reports nothing.
assert_eq!(probe.presented(t0 + Duration::from_millis(40)), None);
}

#[test]
fn an_unanswered_input_expires_when_the_next_one_comes_later() {
let t0 = Instant::now();
let mut probe = InputProbe::default();
assert_eq!(probe.input(InputKind::Query, t0), None);

// A no-op key: nothing is presented, and the next key comes 600 ms on.
let next = t0 + Duration::from_millis(600);
assert_eq!(
probe.input(InputKind::Selection, next),
Some((InputKind::Query, Duration::from_millis(600)))
);
// The new key is measured from its own press.
assert_eq!(
probe.presented(next + Duration::from_millis(1)),
Some((InputKind::Selection, Duration::from_millis(1)))
);
}

#[test]
fn keys_within_the_expiry_still_fold() {
let t0 = Instant::now();
let mut probe = InputProbe::default();
probe.input(InputKind::Query, t0);
assert_eq!(probe.input(InputKind::Query, t0 + INPUT_EXPIRY), None);
assert_eq!(
probe.presented(t0 + INPUT_EXPIRY + Duration::from_millis(2)),
Some((InputKind::Query, INPUT_EXPIRY + Duration::from_millis(2)))
);
}

#[test]
fn a_slow_frame_is_still_reported() {
let t0 = Instant::now();
let mut probe = InputProbe::default();
probe.input(InputKind::Query, t0);
assert_eq!(
probe.presented(t0 + Duration::from_millis(400)),
Some((InputKind::Query, Duration::from_millis(400)))
);
}

#[test]
fn unanswered_inputs_have_their_own_metric() {
assert_eq!(
InputKind::Query.unanswered_metric(),
"query-input-unanswered"
);
assert_eq!(
InputKind::Selection.unanswered_metric(),
"selection-input-unanswered"
);
}
}
Loading