Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

wezterm-gui: read the JSON stores whole instead of a byte per syscall

RoversX03352a53408a
diff --git a/wezterm-gui/src/snippets.rs b/wezterm-gui/src/snippets.rs
index 80773a51..7efbfd2b 100644
--- a/wezterm-gui/src/snippets.rs
+++ b/wezterm-gui/src/snippets.rs
@@ -85,8 +85,8 @@ fn load_snippet_store_from_path(path: &Path) -> Result<SnippetStore> {
if !path.exists() {
return Ok(SnippetStore::default());
}
- let file = fs::File::open(path).with_context(|| format!("open {}", path.display()))?;
- serde_json::from_reader(file).with_context(|| format!("parse {}", path.display()))
+ let text = fs::read_to_string(path).with_context(|| format!("read {}", path.display()))?;
+ serde_json::from_str(&text).with_context(|| format!("parse {}", path.display()))
}
fn save_snippet_store(store: &SnippetStore) -> Result<()> {
diff --git a/wezterm-gui/src/ssh_hosts.rs b/wezterm-gui/src/ssh_hosts.rs
index d5f2dac7..d73a6a62 100644
--- a/wezterm-gui/src/ssh_hosts.rs
+++ b/wezterm-gui/src/ssh_hosts.rs
@@ -73,8 +73,8 @@ fn load_ssh_host_store_from_path(path: &Path) -> Result<SshHostStore> {
if !path.exists() {
return Ok(SshHostStore::default());
}
- let file = fs::File::open(path).with_context(|| format!("open {}", path.display()))?;
- serde_json::from_reader(file).with_context(|| format!("parse {}", path.display()))
+ let text = fs::read_to_string(path).with_context(|| format!("read {}", path.display()))?;
+ serde_json::from_str(&text).with_context(|| format!("parse {}", path.display()))
}
fn save_ssh_host_store(store: &SshHostStore) -> Result<()> {
diff --git a/wezterm-gui/src/termwindow/charselect.rs b/wezterm-gui/src/termwindow/charselect.rs
index 9e1beb46..d32574e8 100644
--- a/wezterm-gui/src/termwindow/charselect.rs
+++ b/wezterm-gui/src/termwindow/charselect.rs
@@ -100,8 +100,8 @@ fn recent_file_name() -> PathBuf {
fn load_recents() -> anyhow::Result<Vec<Recent>> {
let file_name = recent_file_name();
- let f = std::fs::File::open(&file_name)?;
- let mut recents: Vec<Recent> = serde_json::from_reader(f)?;
+ let text = std::fs::read_to_string(&file_name)?;
+ let mut recents: Vec<Recent> = serde_json::from_str(&text)?;
recents.sort_by(|a, b| b.frecency.score().partial_cmp(&a.frecency.score()).unwrap());
Ok(recents)
}
diff --git a/wezterm-gui/src/termwindow/palette.rs b/wezterm-gui/src/termwindow/palette.rs
index 782cabaa..24bfa0ea 100644
--- a/wezterm-gui/src/termwindow/palette.rs
+++ b/wezterm-gui/src/termwindow/palette.rs
@@ -29,8 +29,8 @@ fn recent_file_name() -> PathBuf {
fn load_recents() -> anyhow::Result<Vec<Recent>> {
let file_name = recent_file_name();
- let f = std::fs::File::open(&file_name)?;
- let mut recents: Vec<Recent> = serde_json::from_reader(f)?;
+ let text = std::fs::read_to_string(&file_name)?;
+ let mut recents: Vec<Recent> = serde_json::from_str(&text)?;
recents.sort_by(|a, b| b.frecency.score().partial_cmp(&a.frecency.score()).unwrap());
Ok(recents)
}
diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rs
index 2856dda7..d3633164 100644
--- a/wezterm-gui/src/workspace_threads.rs
+++ b/wezterm-gui/src/workspace_threads.rs
@@ -777,9 +777,12 @@ pub fn load_workspace_thread_store_from_path(path: &Path) -> Result<WorkspaceThr
if !path.exists() {
return Ok(WorkspaceThreadStore::default());
}
- let file = fs::File::open(path).with_context(|| format!("open {}", path.display()))?;
+ // Read whole, then parse: `from_reader` on a bare `File` fetches one
+ // byte per `read` syscall, which for this store is ~140k syscalls on
+ // the main thread before the first window.
+ let text = fs::read_to_string(path).with_context(|| format!("read {}", path.display()))?;
let mut value: serde_json::Value =
- serde_json::from_reader(file).with_context(|| format!("parse {}", path.display()))?;
+ serde_json::from_str(&text).with_context(|| format!("parse {}", path.display()))?;
migrate_legacy_remote_hosts(&value);
let removed = drop_legacy_archived_threads(&mut value);
if removed > 0 {