Use the same background executor for spawning CPU intensive tasks

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Antonio Scandurra
2021-07-13 18:13:25 +02:00
co-authored by Nathan Sobo Max Brunsfeld
parent 6abac39eaa
commit c4e37dc47c
6 changed files with 83 additions and 101 deletions
+3 -9
View File
@@ -34,7 +34,6 @@ pub enum Background {
Deterministic(Arc<Deterministic>),
Production {
executor: Arc<smol::Executor<'static>>,
threads: usize,
_stop: channel::Sender<()>,
},
}
@@ -324,9 +323,8 @@ impl Background {
pub fn new() -> Self {
let executor = Arc::new(Executor::new());
let stop = channel::unbounded::<()>();
let threads = num_cpus::get();
for i in 0..threads {
for i in 0..2 * num_cpus::get() {
let executor = executor.clone();
let stop = stop.1.clone();
thread::Builder::new()
@@ -337,16 +335,12 @@ impl Background {
Self::Production {
executor,
threads,
_stop: stop.0,
}
}
pub fn threads(&self) -> usize {
match self {
Self::Deterministic(_) => 1,
Self::Production { threads, .. } => *threads,
}
pub fn num_cpus(&self) -> usize {
num_cpus::get()
}
pub fn spawn<T, F>(&self, future: F) -> Task<T>