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)
This commit is contained in:
2024-09-28 10:54:54 -06:00
parent ec9731e1e5
commit 2ec17aee9b
2 changed files with 8 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
use std::{
fs::File,
io::{BufReader, BufWriter},
path::{Path, PathBuf},
};
@@ -46,13 +47,13 @@ pub fn load_graphics_config(path: &Path) -> Result<Option<GraphicsConfig>> {
if !path.exists() {
return Ok(None);
}
let file = File::open(path)?;
let file = BufReader::new(File::open(path)?);
let config: GraphicsConfig = ron::de::from_reader(file)?;
Ok(Some(config))
}
pub fn save_graphics_config(path: &Path, config: &GraphicsConfig) -> Result<()> {
let file = File::create(path)?;
let file = BufWriter::new(File::create(path)?);
ron::ser::to_writer(file, config)?;
Ok(())
}