diff options
author | Thomas Linford <tlinford@users.noreply.github.com> | 2021-12-05 11:26:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-05 11:26:32 +0100 |
commit | e47e3d361f27bce179edc34a42e33da4c1b8e091 (patch) | |
tree | 9ffa39e32360dc1ec04c3adaf4a81a64ad560b8e /zellij-client | |
parent | 0a84d39a58f4ac768889cc98d83030046d9dede5 (diff) |
fix(perf): throttle resizes on sigwinch (#895)
Reduce renders while resizing window to reduce performance problem with a large scrollback buffer due to lines recalculation.
Diffstat (limited to 'zellij-client')
-rw-r--r-- | zellij-client/src/os_input_output.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/zellij-client/src/os_input_output.rs b/zellij-client/src/os_input_output.rs index c2fdad826..9b8e84300 100644 --- a/zellij-client/src/os_input_output.rs +++ b/zellij-client/src/os_input_output.rs @@ -10,7 +10,7 @@ use std::io::prelude::*; use std::os::unix::io::RawFd; use std::path::Path; use std::sync::{Arc, Mutex}; -use std::{io, time}; +use std::{io, thread, time}; use zellij_tile::data::Palette; use zellij_utils::{ errors::ErrorContext, @@ -18,6 +18,8 @@ use zellij_utils::{ shared::default_palette, }; +const SIGWINCH_CB_THROTTLE_DURATION: time::Duration = time::Duration::from_millis(50); + fn into_raw_mode(pid: RawFd) { let mut tio = termios::tcgetattr(pid).expect("could not get terminal attribute"); termios::cfmakeraw(&mut tio); @@ -143,10 +145,16 @@ impl ClientOsApi for ClientOsInputOutput { .recv() } fn handle_signals(&self, sigwinch_cb: Box<dyn Fn()>, quit_cb: Box<dyn Fn()>) { + let mut sigwinch_cb_timestamp = time::Instant::now(); let mut signals = Signals::new(&[SIGWINCH, SIGTERM, SIGINT, SIGQUIT, SIGHUP]).unwrap(); for signal in signals.forever() { match signal { SIGWINCH => { + // throttle sigwinch_cb calls, reduce excessive renders while resizing + if sigwinch_cb_timestamp.elapsed() < SIGWINCH_CB_THROTTLE_DURATION { + thread::sleep(SIGWINCH_CB_THROTTLE_DURATION); + } + sigwinch_cb_timestamp = time::Instant::now(); sigwinch_cb(); } SIGTERM | SIGINT | SIGQUIT | SIGHUP => { |