From 425be1e01b024a0b45433676cb2b05b8820b7f0f Mon Sep 17 00:00:00 2001 From: Alexandre Pasmantier <47638216+alexpasmantier@users.noreply.github.com> Date: Sat, 12 Apr 2025 10:29:03 +0000 Subject: [PATCH] fix(ui): fix slight responsiveness regression in 0.11.6 (#461) We were drawing an excessive amount of frames while any channel was in its `running` state which resulted in rendering operations monopolizing CPU resources thus making the application appear less responsive to the user. Fixes #459 --- television/television.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/television/television.rs b/television/television.rs index 637d483..d0f90a0 100644 --- a/television/television.rs +++ b/television/television.rs @@ -288,13 +288,27 @@ impl Television { } } -const RENDER_FIRST_N_TICKS: u64 = 20; -const RENDER_EVERY_N_TICKS: u64 = 10; +/// Always render the first N ticks. +/// +/// This is to ensure there are no startup artefacts and the UI +/// stabilizes rapidly after startup. +const FIRST_TICKS_TO_RENDER: u64 = 10; +/// Render every N ticks. +/// +/// Without any user input, this is the default rendering interval. +const RENDERING_INTERVAL: u64 = 10; +/// Render every N ticks if the channel is currently running. +/// +/// This ensures that the UI stays in sync with the channel +/// state (displaying a spinner, updating results, etc.). +const RENDERING_INTERVAL_FAST: u64 = 3; impl Television { fn should_render(&self, action: &Action) -> bool { - self.ticks < RENDER_FIRST_N_TICKS - || self.ticks % RENDER_EVERY_N_TICKS == 0 + self.ticks < FIRST_TICKS_TO_RENDER + || self.ticks % RENDERING_INTERVAL == 0 + || (self.channel.running() + && self.ticks % RENDERING_INTERVAL_FAST == 0) || matches!( action, Action::AddInputChar(_) @@ -322,7 +336,6 @@ impl Television { | Action::TogglePreview | Action::CopyEntryToClipboard ) - || self.channel.running() } pub fn update_preview_state(