From 25255d90d64ac7e1d5b0fc279bb140b1654a4e8d Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 2 Apr 2023 10:20:39 -0700 Subject: [PATCH] config: lazyily produce ssh domain list I noticed that in debug builds, `wezterm set-working-directory` had high/variable latency, and I traced part of it to the ssh config parsing logic. Make that lazily evaluate the ssh config. refs: #3402 --- config/src/config.rs | 21 +++++++++++++++++---- wezterm-gui/src/main.rs | 4 ++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/config/src/config.rs b/config/src/config.rs index f45676749..7ff37c316 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -325,8 +325,8 @@ pub struct Config { #[dynamic(default = "UnixDomain::default_unix_domains")] pub unix_domains: Vec, - #[dynamic(default = "SshDomain::default_domains")] - pub ssh_domains: Vec, + #[dynamic(default)] + pub ssh_domains: Option>, #[dynamic(default)] pub ssh_backend: SshBackend, @@ -828,6 +828,17 @@ impl Config { Self::load_with_overrides(&wezterm_dynamic::Value::default()) } + /// It is relatively expensive to parse all the ssh config files, + /// so we defer producing the default list until someone explicitly + /// asks for it + pub fn ssh_domains(&self) -> Vec { + if let Some(domains) = &self.ssh_domains { + domains.clone() + } else { + SshDomain::default_domains() + } + } + pub fn update_ulimit(&self) -> anyhow::Result<()> { #[cfg(unix)] { @@ -1127,8 +1138,10 @@ impl Config { for d in &self.unix_domains { check_domain(&d.name, "unix domain")?; } - for d in &self.ssh_domains { - check_domain(&d.name, "ssh domain")?; + if let Some(domains) = &self.ssh_domains { + for d in domains { + check_domain(&d.name, "ssh domain")?; + } } for d in &self.exec_domains { check_domain(&d.name, "exec domain")?; diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index c59158a24..c9e47ed52 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -250,7 +250,7 @@ fn client_domains(config: &config::ConfigHandle) -> Vec { domains.push(ClientDomainConfig::Unix(unix_dom.clone())); } - for ssh_dom in &config.ssh_domains { + for ssh_dom in config.ssh_domains().into_iter() { if ssh_dom.multiplexing == SshMultiplexing::WezTerm { domains.push(ClientDomainConfig::Ssh(ssh_dom.clone())); } @@ -341,7 +341,7 @@ fn update_mux_domains(config: &ConfigHandle) -> anyhow::Result<()> { mux.add_domain(&domain); } - for ssh_dom in &config.ssh_domains { + for ssh_dom in config.ssh_domains().into_iter() { if ssh_dom.multiplexing != SshMultiplexing::None { continue; }