From 6eff8b2c6d01ddac74c6a5ffa2630877be7555d8 Mon Sep 17 00:00:00 2001 From: Tarasov Aleksandr <55220741+arabianq@users.noreply.github.com> Date: Wed, 9 Sep 2026 13:15:05 +0300 Subject: [PATCH] perf(gui): eliminate allocations during cache file read using BufReader (#192) * 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> * small reformatting --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- pwsp-gui/src/gui/mod.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pwsp-gui/src/gui/mod.rs b/pwsp-gui/src/gui/mod.rs index 5f0c8bf..eae7e28 100644 --- a/pwsp-gui/src/gui/mod.rs +++ b/pwsp-gui/src/gui/mod.rs @@ -23,6 +23,7 @@ use std::{ collections::{HashMap, HashSet}, fs, hash::{DefaultHasher, Hash, Hasher}, + io::BufReader, path::{Path, PathBuf}, sync::{Arc, Mutex}, thread, @@ -175,11 +176,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) = fs::File::open(&cache_file) + && let Ok((all_files, dir_updates)) = + serde_json::from_reader(BufReader::new(file)) { finished_scans.lock().unwrap().push(( path_clone.clone(),