From 903dd3e44bf7b4caf09b61976d3eede09b6492ec Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 6 Sep 2026 20:24:32 +0000 Subject: [PATCH] perf: eliminate allocations during cache file read using BufReader Replaced `fs::read_to_string` combined with `serde_json::from_str` with `std::fs::File::open` and `serde_json::from_reader(std::io::BufReader::new(file))`. This avoids loading the entire JSON file into a string allocation before parsing it, improving memory usage. Co-authored-by: arabianq <55220741+arabianq@users.noreply.github.com> --- pwsp-gui/src/gui/mod.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pwsp-gui/src/gui/mod.rs b/pwsp-gui/src/gui/mod.rs index 1dff3fa..f6135e4 100644 --- a/pwsp-gui/src/gui/mod.rs +++ b/pwsp-gui/src/gui/mod.rs @@ -171,11 +171,9 @@ impl SoundpadGui { // 1. Try to load from disk cache if we don't have it in memory yet if !is_cached - && let Ok(data) = fs::read_to_string(&cache_file) - && let Ok((all_files, dir_updates)) = serde_json::from_str::<( - Vec, - HashMap>, - )>(&data) + && let Ok(file) = std::fs::File::open(&cache_file) + && let Ok((all_files, dir_updates)) = + serde_json::from_reader(std::io::BufReader::new(file)) { finished_scans.lock().unwrap().push(( path_clone.clone(),