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
This commit is contained in:
Alexandre Pasmantier 2025-04-12 10:29:03 +00:00 committed by GitHub
parent de6200e45d
commit 425be1e01b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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(