1
0
mirror of https://github.com/bobwen-dev/hunter synced 2025-04-12 00:55:41 +02:00

reduce latency by not running in unnecessary thread pool

reduce latency by not running in unnecessary thread pool
This commit is contained in:
rabite 2020-02-12 18:49:55 +01:00
parent 26017763ed
commit 77fdb0a754
2 changed files with 23 additions and 34 deletions

View File

@ -393,26 +393,21 @@ impl Files {
} }
pub fn enqueue_jobs(&mut self, n: usize) { pub fn enqueue_jobs(&mut self, n: usize) {
let pool = get_pool();
let from = self.meta_upto.unwrap_or(0); let from = self.meta_upto.unwrap_or(0);
self.meta_upto = Some(from + n); self.meta_upto = Some(from + n);
let mut jobs = let cache = match self.cache.clone() {
pool.install(|| {
let c = match self.cache.clone() {
Some(cache) => cache, Some(cache) => cache,
None => return vec![] None => return
}; };
self.iter_files_mut() let mut jobs = self.iter_files_mut()
.skip(from)
.take(n)
// To turn into IndexedParallelIter
.collect::<Vec<&mut File>>() .collect::<Vec<&mut File>>()
.into_par_iter() .into_par_iter()
.filter_map(|f| f.prepare_meta_job(&c)) .skip(from)
.collect::<Vec<_>>() .take(n)
}); .filter_map(|f| f.prepare_meta_job(&cache))
.collect::<Vec<_>>();
self.jobs.append(&mut jobs); self.jobs.append(&mut jobs);
} }

View File

@ -300,9 +300,6 @@ impl FileListBuilder {
} }
pub fn build(mut self) -> HResult<ListView<Files>> { pub fn build(mut self) -> HResult<ListView<Files>> {
// Create new IO pool to not block the main render pool, or other busy IO pools
let pool = crate::files::get_pool();
let c = &self.cache; let c = &self.cache;
let s = self.stale.clone(); let s = self.stale.clone();
let core = self.core; let core = self.core;
@ -316,8 +313,8 @@ impl FileListBuilder {
_ => false _ => false
}; };
let files = pool.install(|| -> HResult<Files> { let mut files =
let mut files = match source { match source {
FileSource::Files(f) => Ok(f), FileSource::Files(f) => Ok(f),
FileSource::Path(f) => { FileSource::Path(f) => {
c.as_ref() c.as_ref()
@ -338,9 +335,6 @@ impl FileListBuilder {
files.sort(); files.sort();
} }
Ok(files)
})?;
let mut view = ListView::new(&core, files); let mut view = ListView::new(&core, files);
selected_file selected_file