mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-09-20 14:13:32 +00:00
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>
This commit is contained in:
co-authored by
google-labs-jules[bot]
parent
dd13eee0df
commit
6eff8b2c6d
@@ -23,6 +23,7 @@ use std::{
|
|||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
fs,
|
fs,
|
||||||
hash::{DefaultHasher, Hash, Hasher},
|
hash::{DefaultHasher, Hash, Hasher},
|
||||||
|
io::BufReader,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
thread,
|
thread,
|
||||||
@@ -175,11 +176,9 @@ impl SoundpadGui {
|
|||||||
|
|
||||||
// 1. Try to load from disk cache if we don't have it in memory yet
|
// 1. Try to load from disk cache if we don't have it in memory yet
|
||||||
if !is_cached
|
if !is_cached
|
||||||
&& let Ok(data) = fs::read_to_string(&cache_file)
|
&& let Ok(file) = fs::File::open(&cache_file)
|
||||||
&& let Ok((all_files, dir_updates)) = serde_json::from_str::<(
|
&& let Ok((all_files, dir_updates)) =
|
||||||
Vec<PathBuf>,
|
serde_json::from_reader(BufReader::new(file))
|
||||||
HashMap<PathBuf, Vec<PathBuf>>,
|
|
||||||
)>(&data)
|
|
||||||
{
|
{
|
||||||
finished_scans.lock().unwrap().push((
|
finished_scans.lock().unwrap().push((
|
||||||
path_clone.clone(),
|
path_clone.clone(),
|
||||||
|
|||||||
Reference in New Issue
Block a user