Skip to content

Commit

Permalink
config: lazyily produce ssh domain list
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wez committed Apr 2, 2023
1 parent 5be7f93 commit 25255d9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 17 additions & 4 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ pub struct Config {
#[dynamic(default = "UnixDomain::default_unix_domains")]
pub unix_domains: Vec<UnixDomain>,

#[dynamic(default = "SshDomain::default_domains")]
pub ssh_domains: Vec<SshDomain>,
#[dynamic(default)]
pub ssh_domains: Option<Vec<SshDomain>>,

#[dynamic(default)]
pub ssh_backend: SshBackend,
Expand Down Expand Up @@ -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<SshDomain> {
if let Some(domains) = &self.ssh_domains {
domains.clone()
} else {
SshDomain::default_domains()
}
}

pub fn update_ulimit(&self) -> anyhow::Result<()> {
#[cfg(unix)]
{
Expand Down Expand Up @@ -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")?;
Expand Down
4 changes: 2 additions & 2 deletions wezterm-gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ fn client_domains(config: &config::ConfigHandle) -> Vec<ClientDomainConfig> {
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()));
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 25255d9

Please sign in to comment.