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(|| { Some(cache) => cache,
let c = match self.cache.clone() { None => return
Some(cache) => cache, };
None => return vec![]
};
self.iter_files_mut() let mut jobs = self.iter_files_mut()
.skip(from) .collect::<Vec<&mut File>>()
.take(n) .into_par_iter()
// To turn into IndexedParallelIter .skip(from)
.collect::<Vec<&mut File>>() .take(n)
.into_par_iter() .filter_map(|f| f.prepare_meta_job(&cache))
.filter_map(|f| f.prepare_meta_job(&c)) .collect::<Vec<_>>();
.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()
@ -327,25 +324,22 @@ impl FileListBuilder {
} }
}?; }?;
// Check/set hidden flag and recalculate number of files if it's different // Check/set hidden flag and recalculate number of files if it's different
if !files.show_hidden == cfg.show_hidden() { if !files.show_hidden == cfg.show_hidden() {
files.show_hidden = cfg.show_hidden(); files.show_hidden = cfg.show_hidden();
files.recalculate_len(); files.recalculate_len();
} }
// TODO: Fix sorting so it works with lazy/partial sorting // TODO: Fix sorting so it works with lazy/partial sorting
if !nosort { if !nosort {
files.sort(); files.sort();
} }
Ok(files)
})?;
let mut view = ListView::new(&core, files); let mut view = ListView::new(&core, files);
selected_file selected_file
.or_else(|| c.as_ref() .or_else(|| c.as_ref()
.and_then(|c| c.get_selection(&view.content.directory).ok())) .and_then(|c| c.get_selection(&view.content.directory).ok()))
.map(|f| view.select_file(&f)); .map(|f| view.select_file(&f));
self.stale.map(|s| view.content.stale = Some(s)); self.stale.map(|s| view.content.stale = Some(s));