Don't spawn a new thread for fresh jobs

The overhead in doing so is often much higher than the actual time it
takes to execute the job
This commit is contained in:
bjorn3 2020-11-07 14:19:14 +01:00
parent 1fc37008e1
commit 0c5f6f012e

View File

@ -880,10 +880,17 @@ impl<'cfg> DrainState<'cfg> {
};
match fresh {
Freshness::Fresh => self.timings.add_fresh(),
Freshness::Dirty => self.timings.add_dirty(),
Freshness::Fresh => {
self.timings.add_fresh();
// Running a fresh job on the same thread is often much faster than spawning a new
// thread to run the job.
doit();
}
Freshness::Dirty => {
self.timings.add_dirty();
scope.spawn(move |_| doit());
}
}
scope.spawn(move |_| doit());
Ok(())
}