Skip to content

Commit 2ec17ae

Browse files
committed
Improve config read/write performance
We were accidentally using unbuffered readers and writers before, leading to long pauses on the main thread on slow filesystems. (e.g. FUSE or WSL)
1 parent ec9731e commit 2ec17ae

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

objdiff-core/src/config/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
fs::File,
3-
io::Read,
3+
io::{BufReader, Read},
44
path::{Path, PathBuf},
55
};
66

@@ -156,7 +156,7 @@ pub struct ProjectConfigInfo {
156156
pub fn try_project_config(dir: &Path) -> Option<(Result<ProjectConfig>, ProjectConfigInfo)> {
157157
for filename in CONFIG_FILENAMES.iter() {
158158
let config_path = dir.join(filename);
159-
let Ok(mut file) = File::open(&config_path) else {
159+
let Ok(file) = File::open(&config_path) else {
160160
continue;
161161
};
162162
let metadata = file.metadata();
@@ -165,9 +165,10 @@ pub fn try_project_config(dir: &Path) -> Option<(Result<ProjectConfig>, ProjectC
165165
continue;
166166
}
167167
let ts = FileTime::from_last_modification_time(&metadata);
168+
let mut reader = BufReader::new(file);
168169
let mut result = match filename.contains("json") {
169-
true => read_json_config(&mut file),
170-
false => read_yml_config(&mut file),
170+
true => read_json_config(&mut reader),
171+
false => read_yml_config(&mut reader),
171172
};
172173
if let Ok(config) = &result {
173174
// Validate min_version if present

objdiff-gui/src/views/graphics.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{
22
fs::File,
3+
io::{BufReader, BufWriter},
34
path::{Path, PathBuf},
45
};
56

@@ -46,13 +47,13 @@ pub fn load_graphics_config(path: &Path) -> Result<Option<GraphicsConfig>> {
4647
if !path.exists() {
4748
return Ok(None);
4849
}
49-
let file = File::open(path)?;
50+
let file = BufReader::new(File::open(path)?);
5051
let config: GraphicsConfig = ron::de::from_reader(file)?;
5152
Ok(Some(config))
5253
}
5354

5455
pub fn save_graphics_config(path: &Path, config: &GraphicsConfig) -> Result<()> {
55-
let file = File::create(path)?;
56+
let file = BufWriter::new(File::create(path)?);
5657
ron::ser::to_writer(file, config)?;
5758
Ok(())
5859
}

0 commit comments

Comments
 (0)