Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Build::compile_objects perf regression and deadlock #849

Merged
merged 2 commits into from
Aug 7, 2023
Merged

Fix Build::compile_objects perf regression and deadlock #849

merged 2 commits into from
Aug 7, 2023

Conversation

NobodyXu
Copy link
Collaborator

@NobodyXu NobodyXu commented Aug 4, 2023

  • Fix perf regression by using Child::try_wait and mpsc::Receiver::try_recv to wait on
    multiple processes and the channel concurrently, and
    thread::yield_now() if no progress is made.
  • Fix the potential deadlock by waiting for all threads to be done and release all the jobserver tokens.

Signed-off-by: Jiahao XU Jiahao_XU@outlook.com

Fixed  #844

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
@twistedfall
Copy link

I can confirm that this fixes the performance regression that I'm experiencing at 1.0.81

@NobodyXu
Copy link
Collaborator Author

NobodyXu commented Aug 5, 2023

I can confirm that this fixes the performance regression that I'm experiencing at 1.0.81

Thank you for testing!

I also wonder if it improves performance, the original PR is intended to improve performance by dramatically reducing number of threads spawned and joined.

@twistedfall
Copy link

Well, if it does, then marginally, in some of my tests I got some times with the patch that were about half a second under the times with 1.0.79, but then again in some tests it finished in about half a second slower :)

@NobodyXu
Copy link
Collaborator Author

NobodyXu commented Aug 6, 2023

Well, if it does, then marginally, in some of my tests I got some times with the patch that were about half a second under the times with 1.0.79, but then again in some tests it finished in about half a second slower :)

Thanks, I guess modern hardware are a bit too powerful.

@twistedfall Can you push it to GitHub and check whether it improve CI run-time?
GitHub CI are overloaded, have only two vCPUs on Linux and Windows by default, so I think it could be helpful in that scenario.

@twistedfall
Copy link

Setting up CI with a custom patched cc-rs specifically for this it a bit of a hassle to be honest, sorry :) But I did run tests locally with -j2 flag passed to cargo which resulted in the same behavior, the amount of concurrently running jobs was limited to 2. And the performance difference is similarly negligible between 1.0.79 and 1.0.81 with the patch from this PR applied.

@NobodyXu
Copy link
Collaborator Author

NobodyXu commented Aug 7, 2023

Setting up CI with a custom patched cc-rs specifically for this it a bit of a hassle to be honest, sorry :) But I did run tests locally with -j2 flag passed to cargo which resulted in the same behavior, the amount of concurrently running jobs was limited to 2. And the performance difference is similarly negligible between 1.0.79 and 1.0.81 with the patch from this PR applied.

Thank you very much!
I guess we would have to roll out this PR first and see whether it does speedup the CI.

cc @thomcc This PR fixed a potential deadlock and a known performance regression.
I will open a PR for new release this time so you can approve and merge it.

src/lib.rs Outdated Show resolved Hide resolved
by using `Child::try_wait` and `mpsc::Receiver::try_recv` to wait on
multiple processes and the channel concurrently, and
`thread::yield_now()` if no progress is made.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
@NobodyXu NobodyXu requested a review from thomcc August 7, 2023 03:45
Copy link
Member

@thomcc thomcc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for now. I will think about this more, but that should not block getting this fix to users.

@thomcc thomcc merged commit 6f43cf3 into rust-lang:main Aug 7, 2023
16 checks passed
@NobodyXu NobodyXu deleted the fix/regression branch August 7, 2023 03:47
@NobodyXu
Copy link
Collaborator Author

NobodyXu commented Aug 7, 2023

@twistedfall cc v1.0.82 has released!

@newpavlov
Copy link

Use of retain_mut has bumped MSRV to 1.61, it has broken CI for the kem crate. At the very least, I believe it should be mentioned in release notes.

@NobodyXu
Copy link
Collaborator Author

That's definitely not intended...I thought the msrv would check that, but it doesn't enable feature parallel.

@newpavlov
Copy link

Do you plan to remove the use of retain_mut or leave as-is? I guess we could bump MSRV of kem from 1.60 to 1.61, though, unfortunately, it will go against our MSRV policy.

@thomcc
Copy link
Member

thomcc commented Sep 27, 2023

It's a release over a year old and was unintentional, so I wouldn't fix it on my own, but I would accept a patch fixing it if it's reasonable (with no guarantee that we won't bump the MSRV again in a future release -- it would be in the relnotes next time though).

Definitely the CI detection should be fixed, however.

EDIT: Note that I can't promise a release of cc until the weekend though.

@NobodyXu
Copy link
Collaborator Author

retain_mut can be replaced with Vec::swap_remove since we don't really care about the order of the Vec anyway, just want to iterate over all the processes and .try_wait() on them..

@newpavlov Unfortunately I have been busy recently so I won't be able to provide a PR in a short time, however I do think it can be done even if you don't have any experience with the cc codebase.

@newpavlov
Copy link

In our case cc was only part of dev dependency tree and new MSRV is just 1 version bigger than one supported by the crate, so we simply tweaked our CI.

@NobodyXu
Copy link
Collaborator Author

That's good to hear, though I will submit a PR to fix this

Wilfred added a commit to Wilfred/difftastic that referenced this pull request Oct 8, 2023
This reverts commit 71bf6b6.

Using the parallel feature on cc requires Rust 1.61 or higher, see
rust-lang/cc-rs#849
@NobodyXu
Copy link
Collaborator Author

@newpavlov @thomcc I've opened #888 to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants