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

Potential performance increases found #300

Open
JackThomson2 opened this issue Sep 29, 2021 · 2 comments
Open

Potential performance increases found #300

JackThomson2 opened this issue Sep 29, 2021 · 2 comments

Comments

@JackThomson2
Copy link

Hi love this library and using it a lot!

I was having a poke through the code and was looking at the adaptive backoff spinning code and putting it into godbolt to see what it was doing. I noticed that LLVM wasn't actually unrolling the loops for the backoff spinning, so I had try at forcing it to do so.

What I found was actually fairly significant performance increases over current master. You can view the code I changed here:
https://rust.godbolt.org/z/f3Psh5end

Here is an example of the performance increases I was getting:

243198540_667188404256577_160126566198274773_n

Compared to master here:

243161101_259130739439988_8653606655075115682_n

Just wondering what your thoughts where? I ran this benchmark multiple times to be sure but the results seemed to be consistently better. If you like the sound of it I can create a PR to make the changes.

Many Thanks

Jack

@Amanieu
Copy link
Owner

Amanieu commented Sep 29, 2021

This is slightly counter-intuitive, but throughput increases when the spin takes longer. The reason for this is that a spinning core isn't fighting with another core for exclusive ownership of a cacheline, which allows a single core to quickly lock/unlock the mutex in succession without interference. While this is good for throughput, it is bad for overall system performance because you end up with a lot of core spinning instead of doing useful work (e.g. background processes).

@JackThomson2
Copy link
Author

I see, but as far as I can tell this isn't doing any less or more spinning, it just seems to call the pause instructions more efficiently.

I could be completely wrong however.

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

No branches or pull requests

2 participants