-
Notifications
You must be signed in to change notification settings - Fork 48
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
Sharded counter optimisation #109
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
Additional details and impacted files
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for pushing this forward!
I took a look at the code for fast-counter
, and had a couple of thoughts:
- I think
THREAD_ID
can be aCell<usize>
instead of anUnsafeCell
. Should let you get rid of theunsafe
block you have in there. - On
nightly
you can useThreadId::as_u64
rather than keepingTHREAD_ID
yourself. - It's not entirely clear to me why you have stable and nightly separated? The use of
#[thread_local]
doesn't feel like it's very important, and in terms of performance the difference seems fairly minor.
Thanks for the feedback, all great points, I'll try address these soon. The reason for the night / stable just happened as an effect of me starting with the nightly first, and originally the performance difference was greater. I left it was an |
Hey @jonhoo been looking into this and a few thoughts and findings:
Thanks again for reviewing this |
Sorry for the super slow reply!
Looking at the
That's super weird! The code for
Nice!
Ah, yes, that's a great point, and a totally valid reason for using an
Thanks for digging so deep! |
Actually, on second thought, in a concurrent setting with lazily updated counters, it's entirely possible that the sum of the counters ends up being negative for some shorter period of time. So I think we should actually leave the return value as an |
let _saw_bin_length = match resize_hint { | ||
Some(hint) => hint, | ||
None => return | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd probably make this an if let Some
Looks like there are some CI failures now? |
I've been following along somewhat closely and happy to see that you guys made good progress. 🎉 If either of you ever need assistance (with anything really) you can always @ me :) (although I'm fairly certain you both got this in the bag). Well done Jack & Jon! |
Saw these, I'll take a look at resolving them when I get a chance! Thanks for running the workflow |
This is picking up from the great work from @jimvdl in this PR: #101
I've added the crate here: https://github.com/JackThomson2/fast-counter which is using a basic sharded concurrent counter which is identified using a thread_local. It seems at worse case it's slightly slower but with more cores it starts to pull ahead.
These are the results using the conc-bench repo on my 16 core machine:
This change is