In one of our projects we're suffering from long build times. We've slowly been multi-threading it where appropriate, shaving a few seconds here and there. One particular pain point is that packaging the debug builds took just over 92 seconds. I decided to spend this Sunday to see if I could get that down a little bit.
Each component is packaged in its own function, they take in an immutable context buffer with all the packaging data and they used to take in a mutable result buffer which each function would use to insert information about the output package. I changed this to return the package information instead, then I changed each call to run in a thread instead, collect all JoinHandle
s in a Vec
, and iterate over them and .join()
and extract the package information for next stage. All in all, pretty trivial changes, once I realized all the input data can be immutable.
The packaging time is now at 28 seconds.
As long as no one decides to sprinkle a few std::env::set_current_dir() in there, I'm confident that it'll yield the expected results. No explicit locks; I completely rely on making sure the borrow-checker is happy.
There are still improvements to be made; currently too many packaging threads are launched simultaneously .. but this far exceeded my expectations; it really made my day.