-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Performance improvement in Count<T> extension #3548
Performance improvement in Count<T> extension #3548
Conversation
Thanks Sergio0694 for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
Gives up to a ~21% performance boost on .NET 5
1912521
to
2e5dce5
Compare
I like optimization, but could the code be wirten in a more maintainable way so that RyuJit would unroll it for us? There seems to be some ongoing discussion (dotnet/runtime#8107) on expanding loop unrolling optimizations. |
Thanks @RosarioPulella! @Sergio0694 would it make sense to find/file dotnet issues for any hand-optimizations like this you're doing that could maybe be improved in the compiler? At least then we could mark out the section of code and link to the issue so we could remove it later when it gets optimized in the runtime? |
Oh, whoops, forgot to reply to this, I'm sorry! 😅 @RosarioPulella The discussion is ongoing but as you can see it's still planned for future (not even .NET 6), and furthermore this case is particularly tricky because the JIT would need to unroll a loop that itself is also already using vectorized instructions, which adds another layer of complexity on top for it to handle. I would argue this is worth it for a few reasons:
@michael-hawker I've already opened a few issues related to things I'm doing in the |
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.
@Sergio0694 You make some really good points and I see the value in these changes.
@RosarioPulella Awesome! Glad we all agree - and those were some absolutely valid questions! 😄 |
Hello @michael-hawker! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
PR Type
What kind of change does this PR introduce?
What is the new behavior?
About 20% improvement on .NET 5 when working on
char
types (or larger):This was done by adding an unrolled loop for the vectorized path of the SIMD accelerated version of
Count<T>
.PR Checklist
Please check if your PR fulfills the following requirements:
Pull Request has been submitted to the documentation repository instructions. Link:Sample in sample app has been added / updated (for bug fixes / features)Icon has been created (if new sample) following the Thumbnail Style Guide and templates