Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(perf): throttle resizes on sigwinch #895

Merged
merged 1 commit into from
Dec 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion zellij-client/src/os_input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ 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,
ipc::{ClientToServerMsg, IpcReceiverWithContext, IpcSenderWithContext, ServerToClientMsg},
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);
Expand Down Expand Up @@ -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 => {
Expand Down