From b98d1001dee5482c3c048bce98bdc07843451900 Mon Sep 17 00:00:00 2001 From: Nils Andreas Svee Date: Tue, 6 Oct 2026 14:39:05 +0700 Subject: [PATCH] perf(tui): optimize graph rendering and increase UI responsiveness Efficiently sample data within the viewport for graph series and reduce the rendering interval for a smoother user experience. --- crates/irtt-app/src/cmd/tui/run.rs | 2 +- crates/irtt-app/src/cmd/tui/ui.rs | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/crates/irtt-app/src/cmd/tui/run.rs b/crates/irtt-app/src/cmd/tui/run.rs index c0a89d0..70fe21e 100644 --- a/crates/irtt-app/src/cmd/tui/run.rs +++ b/crates/irtt-app/src/cmd/tui/run.rs @@ -26,7 +26,7 @@ use tokio::{ time::{sleep, Instant}, }; -const RENDER_INTERVAL: Duration = Duration::from_millis(250); +const RENDER_INTERVAL: Duration = Duration::from_millis(100); pub async fn run_tui( args: TuiArgs, diff --git a/crates/irtt-app/src/cmd/tui/ui.rs b/crates/irtt-app/src/cmd/tui/ui.rs index 8802e15..9dc7f92 100644 --- a/crates/irtt-app/src/cmd/tui/ui.rs +++ b/crates/irtt-app/src/cmd/tui/ui.rs @@ -1272,13 +1272,27 @@ fn target_metric_series( viewport: GraphViewportRange, metric: GraphMetric, ) -> Option { - let points = target.graph_history.iter().filter_map(|sample| { + // Histories are monotonic. Skip old samples without converting every + // retained measurement on each repaint, then keep the nearest valid + // predecessor for interpolation across the left boundary. + let first = target + .graph_history + .partition_point(|sample| sample.timestamp.mono < viewport.start); + let mut previous = target + .graph_history + .range(..first) + .rev() + .find_map(|sample| { + metric + .value_ns(sample) + .map(|ns| (sample.timestamp.mono, ns as f64 / 1_000_000.0)) + }); + let points = target.graph_history.range(first..).filter_map(|sample| { metric .value_ns(sample) .map(|ns| (sample.timestamp.mono, ns as f64 / 1_000_000.0)) }); let mut data = Vec::new(); - let mut previous: Option<(Instant, f64)> = None; for point in points { if let Some(before) = previous { // Only genuine crossing segments contribute boundary points. In @@ -1423,12 +1437,10 @@ fn graph_timestamp_anchor(state: &TuiState, end: Instant) -> Option