-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Unnecessary outer loop in CountBy #106110
Comments
The proposed solution allocates an additional delegate and inner enumerator, whereas the existing code iterates over a struct enumerator. It also makes the code substantially less readable, so this doesn't seem like a clear-cut win to me. Can you share any benchmark numbers? |
BenchmarksRatio 0.92
|
Would it be possible to share results for smaller numbers? It would be interesting to see how it fares with < 10-20 sources and empty sources specifically (since it now allocates an enumerator when it previously didn't). |
I made the code readable and removed delegate allocation. |
I created benchmarks for 1_000_000, 10_00, 100, 1, and 0 elements.
|
Closing per feedback in #106111. |
The implementation of the new CountBy adds an unnecessary outer loop through the dictionary elements.
runtime/src/libraries/System.Linq/src/System/Linq/CountBy.cs
Lines 39 to 42 in 019d758
I think we can return created Dictionary enumerator:
The text was updated successfully, but these errors were encountered: