From e47e3d361f27bce179edc34a42e33da4c1b8e091 Mon Sep 17 00:00:00 2001 From: Thomas Linford Date: Sun, 5 Dec 2021 11:26:32 +0100 Subject: 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. --- zellij-client/src/os_input_output.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'zellij-client') 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, quit_cb: Box) { + 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 => { -- cgit v1.2.3