Replace easy-parallel with scoped-pool for path searches
The easy-parallel crate spawned new threads on each call, which was resulting in way too many threads. Co-Authored-By: Brooks Swinnerton <934497+bswinnerton@users.noreply.github.com>
This commit is contained in:
co-authored by
Brooks Swinnerton
parent
0a2d2aa684
commit
0cc5e8f742
@@ -1,4 +1,4 @@
|
||||
use easy_parallel::Parallel;
|
||||
use gpui::scoped_pool;
|
||||
|
||||
use super::char_bag::CharBag;
|
||||
|
||||
@@ -54,6 +54,7 @@ pub fn match_paths(
|
||||
include_ignored: bool,
|
||||
smart_case: bool,
|
||||
max_results: usize,
|
||||
pool: scoped_pool::Pool,
|
||||
) -> Vec<PathMatch> {
|
||||
let lowercase_query = query.to_lowercase().chars().collect::<Vec<_>>();
|
||||
let query = query.chars().collect::<Vec<_>>();
|
||||
@@ -68,10 +69,9 @@ pub fn match_paths(
|
||||
let segment_size = (path_count + cpus - 1) / cpus;
|
||||
let mut segment_results = (0..cpus).map(|_| BinaryHeap::new()).collect::<Vec<_>>();
|
||||
|
||||
Parallel::new()
|
||||
.each(
|
||||
segment_results.iter_mut().enumerate(),
|
||||
|(segment_idx, results)| {
|
||||
pool.scoped(|scope| {
|
||||
for (segment_idx, results) in segment_results.iter_mut().enumerate() {
|
||||
scope.execute(move || {
|
||||
let segment_start = segment_idx * segment_size;
|
||||
let segment_end = segment_start + segment_size;
|
||||
|
||||
@@ -115,9 +115,9 @@ pub fn match_paths(
|
||||
}
|
||||
tree_start = tree_end;
|
||||
}
|
||||
},
|
||||
)
|
||||
.run();
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
let mut results = segment_results
|
||||
.into_iter()
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::{
|
||||
use anyhow::{anyhow, Result};
|
||||
use crossbeam_channel as channel;
|
||||
use easy_parallel::Parallel;
|
||||
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
|
||||
use gpui::{scoped_pool, AppContext, Entity, ModelContext, ModelHandle, Task};
|
||||
use ignore::dir::{Ignore, IgnoreBuilder};
|
||||
use parking_lot::RwLock;
|
||||
use smol::prelude::*;
|
||||
@@ -606,6 +606,7 @@ pub fn match_paths(
|
||||
include_ignored: bool,
|
||||
smart_case: bool,
|
||||
max_results: usize,
|
||||
pool: scoped_pool::Pool,
|
||||
) -> Vec<PathMatch> {
|
||||
let tree_states = trees.iter().map(|tree| tree.0.read()).collect::<Vec<_>>();
|
||||
fuzzy::match_paths(
|
||||
@@ -634,6 +635,7 @@ pub fn match_paths(
|
||||
include_ignored,
|
||||
smart_case,
|
||||
max_results,
|
||||
pool,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -674,7 +676,7 @@ mod test {
|
||||
app.read(|ctx| {
|
||||
let tree = tree.read(ctx);
|
||||
assert_eq!(tree.file_count(), 4);
|
||||
let results = match_paths(&[tree.clone()], "bna", false, false, 10)
|
||||
let results = match_paths(&[tree.clone()], "bna", false, false, 10, ctx.scoped_pool().clone())
|
||||
.iter()
|
||||
.map(|result| tree.entry_path(result.entry_id))
|
||||
.collect::<Result<Vec<PathBuf>, _>>()
|
||||
|
||||
Reference in New Issue
Block a user