cargo-hack icon indicating copy to clipboard operation
cargo-hack copied to clipboard

Multithreaded mode

Open asomers opened this issue 3 years ago • 7 comments

--each-feature and --feature-powerset are great! My only complaint is that they are slow. bpytop shows that I'm never using more than one core when running cargo-hack. It would be awesome if cargo hack could run multiple cargo processes in parallel, one for each feature combination. Normally Cargo doesn't allow two processes to share the same build directory at the same time, so you could set CARGO_TARGET_DIR to a separate value for each.

There is a little contention for the crate cache, but my crude benchmark shows that I can build targets in parallel in about a quarter of the time it takes to build them sequentially.

asomers avatar Aug 21 '21 23:08 asomers

I think this is a great idea. I would accept a PR to implement this.

taiki-e avatar Aug 22 '21 11:08 taiki-e

I thought about it, but decided that I don't have the time to do it myself.

asomers avatar Sep 04 '21 21:09 asomers

Hey, I was looking around and it seems that this issue hasn't been addressed in quite a long time. Wanting to know, if you are still accepting PR, for this issue.

NishantJoshi00 avatar Jan 16 '23 17:01 NishantJoshi00

@NishantJoshi00 you might want to try #175 that adds a way to get a list of commands out, and then you can run those commands separately for different processes. I'm using that command to run the processes on different machines even.

leighmcculloch avatar Jan 16 '23 17:01 leighmcculloch

Interesting! I was able to come up with a similar solution for improving performance. I achieved parallelization with rayon and have a CARGO_TARGET_DIR pool to also leverage caching. I was planning to raise a PR for this issue too.

NishantJoshi00 avatar Jan 16 '23 17:01 NishantJoshi00

This feature request is no longer as important as it was when I filed it, because rust 1.64.0 supports multitarget builds. So you can now do something like cargo hack check --target i686-linux-android --target x86_64-apple-darwin --target x86_64-apple-ios .... And cargo-hack happily passes all of those targets through to the cargo check command. That provides plenty of parallelism if you have multiple targets to care about. But it still doesn't address the case where the only parallelism comes from different feature sets.

asomers avatar Jan 16 '23 18:01 asomers

Yeah, this is still useful and PR is welcome.

taiki-e avatar Jan 17 '23 01:01 taiki-e