Skip to content

Commit 0c5f6f0

Browse files
committed
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
1 parent 1fc3700 commit 0c5f6f0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/cargo/core/compiler/job_queue.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,10 +880,17 @@ impl<'cfg> DrainState<'cfg> {
880880
};
881881

882882
match fresh {
883-
Freshness::Fresh => self.timings.add_fresh(),
884-
Freshness::Dirty => self.timings.add_dirty(),
883+
Freshness::Fresh => {
884+
self.timings.add_fresh();
885+
// Running a fresh job on the same thread is often much faster than spawning a new
886+
// thread to run the job.
887+
doit();
888+
}
889+
Freshness::Dirty => {
890+
self.timings.add_dirty();
891+
scope.spawn(move |_| doit());
892+
}
885893
}
886-
scope.spawn(move |_| doit());
887894

888895
Ok(())
889896
}

0 commit comments

Comments
 (0)