Parallelize ignored entries for search lookup

This commit is contained in:
Kirill Bulatov 2023-11-23 09:52:57 +02:00
parent 71e9bd8fa3
commit c2751c717e
2 changed files with 18 additions and 11 deletions

View file

@ -62,7 +62,10 @@ use serde::Serialize;
use settings::SettingsStore; use settings::SettingsStore;
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
use similar::{ChangeTag, TextDiff}; use similar::{ChangeTag, TextDiff};
use smol::channel::{Receiver, Sender}; use smol::{
channel::{Receiver, Sender},
lock::Semaphore,
};
use std::{ use std::{
cmp::{self, Ordering}, cmp::{self, Ordering},
convert::TryInto, convert::TryInto,
@ -5744,14 +5747,17 @@ impl Project {
.log_err(); .log_err();
} }
// TODO kb parallelize directory traversal
background background
.scoped(|scope| { .scoped(|scope| {
let max_concurrent_workers = Arc::new(Semaphore::new(workers));
for worker_ix in 0..workers { for worker_ix in 0..workers {
let worker_start_ix = worker_ix * paths_per_worker; let worker_start_ix = worker_ix * paths_per_worker;
let worker_end_ix = worker_start_ix + paths_per_worker; let worker_end_ix = worker_start_ix + paths_per_worker;
let unnamed_buffers = opened_buffers.clone(); let unnamed_buffers = opened_buffers.clone();
let limiter = Arc::clone(&max_concurrent_workers);
scope.spawn(async move { scope.spawn(async move {
let _guard = limiter.acquire().await;
let mut snapshot_start_ix = 0; let mut snapshot_start_ix = 0;
let mut abs_path = PathBuf::new(); let mut abs_path = PathBuf::new();
for snapshot in snapshots { for snapshot in snapshots {
@ -5815,12 +5821,14 @@ impl Project {
} }
if query.include_ignored() { if query.include_ignored() {
scope.spawn(async move { for snapshot in snapshots {
for snapshot in snapshots { for ignored_entry in snapshot
for ignored_entry in snapshot .entries(query.include_ignored())
.entries(query.include_ignored()) .filter(|e| e.is_ignored)
.filter(|e| e.is_ignored) {
{ let limiter = Arc::clone(&max_concurrent_workers);
scope.spawn(async move {
let _guard = limiter.acquire().await;
let mut ignored_paths_to_process = let mut ignored_paths_to_process =
VecDeque::from([snapshot.abs_path().join(&ignored_entry.path)]); VecDeque::from([snapshot.abs_path().join(&ignored_entry.path)]);
while let Some(ignored_abs_path) = while let Some(ignored_abs_path) =
@ -5895,9 +5903,9 @@ impl Project {
} }
} }
} }
} });
} }
}); }
} }
}) })
.await; .await;

View file

@ -219,7 +219,6 @@ impl ProjectSearch {
this.no_results = Some(true); this.no_results = Some(true);
}); });
// TODO kb check for cancellations here and actually stop the search?
while let Some((buffer, anchors)) = matches.next().await { while let Some((buffer, anchors)) = matches.next().await {
let mut ranges = this.update(&mut cx, |this, cx| { let mut ranges = this.update(&mut cx, |this, cx| {
this.no_results = Some(false); this.no_results = Some(false);