From 67673e31c237f47e90bef059e28c34ecf8951221 Mon Sep 17 00:00:00 2001 From: Franklin Delehelle Date: Thu, 27 Oct 2022 16:49:27 +0200 Subject: [PATCH] Improve subb-fragments performances --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/fs.rs | 17 +++++++++-------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b1e7783..c141de6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -356,6 +356,7 @@ dependencies = [ "log", "maplit", "memmap2", + "multi-map", "notify-rust", "num-format", "regex", @@ -572,6 +573,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "multi-map" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bba551d6d795f74a01767577ea8339560bf0a65354e0417b7e915ed608443d46" + [[package]] name = "nix" version = "0.23.1" diff --git a/Cargo.toml b/Cargo.toml index 37d74c8..caf920b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ libc = "0.2" log = "0.4" maplit = "1.0" memmap2 = "0.5" +multi-map = "1.3" notify-rust = { version = "4", optional = true } num-format = "0.4" regex = "1" diff --git a/src/fs.rs b/src/fs.rs index ecd4ae3..3afcb74 100755 --- a/src/fs.rs +++ b/src/fs.rs @@ -5,6 +5,7 @@ use fuser::*; use libc::*; use log::*; use maplit::*; +use multi_map::MultiMap; use regex::Regex; use smartstring::SmartString; use std::cell::RefCell; @@ -447,7 +448,7 @@ pub struct FustaFS { pending_appends: BTreeMap, - subfragments: Vec, + subfragments: MultiMap, // name -> inode -> SubFragment dirty: bool, } @@ -495,8 +496,8 @@ impl FustaFS { metadata, settings, current_ino: FIRST_INO, - pending_appends: BTreeMap::new(), - subfragments: Vec::new(), + pending_appends: Default::default(), + subfragments: Default::default(), dirty: false, }; @@ -725,7 +726,7 @@ impl FustaFS { } fn subfragment_from_ino(&self, ino: u64) -> Option<&SubFragment> { - self.subfragments.iter().find(|sf| sf.attrs.ino == ino) + self.subfragments.get_alt(&ino) } fn make_info_buffer(&mut self) { @@ -901,17 +902,17 @@ impl FustaFS { let end = str::parse::(&caps[3]) .map_err(|_| format!("{}: `{}` is not an integer", &error_message, &caps[2]))?; let (start, end) = clear_coordinates(start, end); + let key = format!("{}:{}-{}", fragment_id, start, end); self.subfragments - .iter() - .find(|sf| sf.fragment == fragment_id && sf.start == start && sf.end == end) + .get(&key) .map(|sf| sf.attrs) .or_else(|| { let size = (end - start) as u64; let mut attrs = FustaFS::make_file_attrs(ino, 0o444); attrs.size = size; let sf = SubFragment::new(&fragment_id, start, end, attrs); - self.subfragments.push(sf); + self.subfragments.insert(key, ino, sf); Some(attrs) }) .ok_or_else(|| unimplemented!()) @@ -928,7 +929,7 @@ impl FustaFS { let mut attrs = FustaFS::make_file_attrs(ino, 0o444); attrs.size = fragment_len as u64; let sf = SubFragment::new(&fragment_id, 0, fragment_len.try_into().unwrap(), attrs); - self.subfragments.push(sf); + self.subfragments.insert(name.to_owned(), ino, sf); Ok(attrs) } }