Initialize tokio once #10

closed
opened by danabra.mov targeting main

for perf

Changed files
+9 -5
src
+9 -5
src/fs.rs
··· 1 - use std::time::{self, SystemTime, UNIX_EPOCH, Duration}; 1 + use std::time::{self, Duration, SystemTime, UNIX_EPOCH}; 2 2 3 3 use atrium_repo::{Repository, blockstore::AsyncBlockStoreRead}; 4 4 use futures::StreamExt; ··· 30 30 pub struct PdsFs<R> { 31 31 repos: IndexMap<String, Repository<R>>, 32 32 inodes: IndexSet<PdsFsEntry>, 33 + rt: tokio::runtime::Runtime, 33 34 } 34 35 35 36 #[derive(Debug, Clone, PartialEq, Eq, Hash)] ··· 112 113 PdsFs { 113 114 repos: Default::default(), 114 115 inodes: IndexSet::from([PdsFsEntry::Zero, PdsFsEntry::Root]), 116 + rt: tokio::runtime::Runtime::new().unwrap(), 115 117 } 116 118 } 117 119 ··· 185 187 let did = self.inodes[col.parent].unwrap_did(); 186 188 let repo = &mut self.repos[did]; 187 189 let key = format!("{}/{}", col.nsid, r.rkey); 188 - let rt = tokio::runtime::Runtime::new().unwrap(); 189 - let size = rt 190 + let size = self 191 + .rt 190 192 .block_on(repo.get_raw::<ipld_core::ipld::Ipld>(&key)) 191 193 .ok() 192 194 .flatten() ··· 402 404 _lock: Option<u64>, 403 405 reply: fuser::ReplyData, 404 406 ) { 405 - let rt = tokio::runtime::Runtime::new().unwrap(); 406 407 if let Some(PdsFsEntry::Record(r)) = self.inodes.get_index(ino as usize) { 407 408 let col = self.inodes[r.parent].unwrap_collection(); 408 409 let did = self.inodes[col.parent].unwrap_did(); 409 410 let repo = &mut self.repos[did]; 410 411 let key = format!("{}/{}", col.nsid, r.rkey); 411 412 412 - if let Ok(Some(val)) = rt.block_on(repo.get_raw::<ipld_core::ipld::Ipld>(&key)) { 413 + if let Ok(Some(val)) = self 414 + .rt 415 + .block_on(repo.get_raw::<ipld_core::ipld::Ipld>(&key)) 416 + { 413 417 reply.data(&serde_json::to_string(&val).unwrap().as_bytes()[offset as usize..]); 414 418 return; 415 419 }