From 39086c048b75d8dcd2511bfb18aded292fb9b5c3 Mon Sep 17 00:00:00 2001 From: Quentin Perret Date: Fri, 7 Jan 2022 14:49:51 +0000 Subject: [PATCH] Make the threshold for predictive echo configurable Introduce a new config knob called 'local_echo_threshold_ms' to let users configure when the local echo prediction should kick in. The default value is 100ms to retain the current behavior. --- config/src/config.rs | 4 ++++ config/src/ssh.rs | 3 +++ config/src/tls.rs | 3 +++ config/src/unix.rs | 5 +++++ wezterm-client/src/domain.rs | 19 +++++++++++++++++-- wezterm-client/src/pane/renderable.rs | 6 ++++-- 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/config/src/config.rs b/config/src/config.rs index ba6dcfa57..938d2db57 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -1126,6 +1126,10 @@ pub fn default_write_timeout() -> Duration { Duration::from_secs(60) } +pub fn default_local_echo_threshold_ms() -> Option { + Some(100) +} + fn default_bypass_mouse_reporting_modifiers() -> Modifiers { Modifiers::SHIFT } diff --git a/config/src/ssh.rs b/config/src/ssh.rs index 4f2641028..51e0f504b 100644 --- a/config/src/ssh.rs +++ b/config/src/ssh.rs @@ -70,6 +70,9 @@ pub struct SshDomain { #[serde(default = "default_read_timeout")] pub timeout: Duration, + #[serde(default = "default_local_echo_threshold_ms")] + pub local_echo_threshold_ms: Option, + /// The path to the wezterm binary on the remote host pub remote_wezterm_path: Option, diff --git a/config/src/tls.rs b/config/src/tls.rs index ba569a5ea..ed031c46c 100644 --- a/config/src/tls.rs +++ b/config/src/tls.rs @@ -80,6 +80,9 @@ pub struct TlsDomainClient { #[serde(default = "default_write_timeout")] pub write_timeout: Duration, + #[serde(default = "default_local_echo_threshold_ms")] + pub local_echo_threshold_ms: Option, + /// The path to the wezterm binary on the remote host pub remote_wezterm_path: Option, } diff --git a/config/src/unix.rs b/config/src/unix.rs index 79d6d6404..0bd9ed3d8 100644 --- a/config/src/unix.rs +++ b/config/src/unix.rs @@ -48,6 +48,10 @@ pub struct UnixDomain { #[serde(default = "default_write_timeout")] pub write_timeout: Duration, + + /// Don't use default_local_echo_threshold_ms() here to + /// disable the predictive echo for Unix domains by default. + pub local_echo_threshold_ms: Option, } impl_lua_conversion!(UnixDomain); @@ -62,6 +66,7 @@ impl Default for UnixDomain { skip_permissions_check: false, read_timeout: default_read_timeout(), write_timeout: default_write_timeout(), + local_echo_threshold_ms: None, proxy_command: None, } } diff --git a/wezterm-client/src/domain.rs b/wezterm-client/src/domain.rs index acd3c4f22..4ea0c0eb4 100644 --- a/wezterm-client/src/domain.rs +++ b/wezterm-client/src/domain.rs @@ -22,6 +22,7 @@ pub struct ClientInner { pub client: Client, pub local_domain_id: DomainId, pub remote_domain_id: DomainId, + pub local_echo_threshold_ms: Option, remote_to_local_window: Mutex>, remote_to_local_tab: Mutex>, remote_to_local_pane: Mutex>, @@ -128,6 +129,14 @@ impl ClientDomainConfig { } } + pub fn local_echo_threshold_ms(&self) -> Option { + match self { + ClientDomainConfig::Unix(unix) => unix.local_echo_threshold_ms, + ClientDomainConfig::Tls(tls) => tls.local_echo_threshold_ms, + ClientDomainConfig::Ssh(ssh) => ssh.local_echo_threshold_ms, + } + } + pub fn label(&self) -> String { match self { ClientDomainConfig::Unix(unix) => format!("unix mux {}", unix.socket_path().display()), @@ -152,7 +161,11 @@ impl ClientDomainConfig { } impl ClientInner { - pub fn new(local_domain_id: DomainId, client: Client) -> Self { + pub fn new( + local_domain_id: DomainId, + client: Client, + local_echo_threshold_ms: Option, + ) -> Self { // Assumption: that the domain id on the other end is // always the first created default domain. In the future // we'll add a way to discover/enumerate domains to populate @@ -162,6 +175,7 @@ impl ClientInner { client, local_domain_id, remote_domain_id, + local_echo_threshold_ms, remote_to_local_window: Mutex::new(HashMap::new()), remote_to_local_tab: Mutex::new(HashMap::new()), remote_to_local_pane: Mutex::new(HashMap::new()), @@ -407,8 +421,9 @@ impl ClientDomain { let domain = domain .downcast_ref::() .ok_or_else(|| anyhow!("domain {} is not a ClientDomain", domain_id))?; + let threshold = domain.config.local_echo_threshold_ms(); - let inner = Arc::new(ClientInner::new(domain_id, client)); + let inner = Arc::new(ClientInner::new(domain_id, client, threshold)); *domain.inner.borrow_mut() = Some(Arc::clone(&inner)); Self::process_pane_list(inner, panes)?; diff --git a/wezterm-client/src/pane/renderable.rs b/wezterm-client/src/pane/renderable.rs index af1b3f0d6..1b0267145 100644 --- a/wezterm-client/src/pane/renderable.rs +++ b/wezterm-client/src/pane/renderable.rs @@ -133,9 +133,11 @@ impl RenderableInner { /// Predictive echo can be noisy when the link is working well, /// so we only employ it when it looks like the latency is high. - /// We pick 100ms as the threshold for this. fn should_predict(&self) -> bool { - !self.client.is_local() && self.last_input_rtt >= 100 + self.client + .local_echo_threshold_ms + .map(|thresh| self.last_input_rtt >= thresh) + .unwrap_or(false) } /// Compute a "prediction" and apply it to the line data that we