-
Notifications
You must be signed in to change notification settings - Fork 416
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
Improve list optimisation in CountDown
#942
Improve list optimisation in CountDown
#942
Conversation
Two things:
|
45% improvement:
Yes, I am aware and admit taking a shortcut there. The difference was large enough and comparable in the many runs I did. What's more important is the comparison between list and sequence processing in the same ran than between the before and after |
Codecov Report
@@ Coverage Diff @@
## master #942 +/- ##
==========================================
- Coverage 92.42% 92.41% -0.01%
==========================================
Files 112 112
Lines 3446 3442 -4
Branches 1023 1023
==========================================
- Hits 3185 3181 -4
Misses 199 199
Partials 62 62
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
CountDown
has a path optimised for when thesource
parameter is a list, but it was poorly written respect to performance. It accessed the listCount
property 3 times, twice during each iteration of the loop. Each access is a virtual dispatch so it seems to adds up, making it perform worse than when the source is a sequence (zero net optimisation). This PR fixes that by accessingCount
once, storing it in a local and then using the local throughout. This improves the performance by 40%.Before this PR
See
benchmarks-before.log.txt
for full details.After this PR
See
benchmarks-after.log.txt
for full details.Additional Information
See also:
Benchmark.linq
for benchmarking code for LINQPad.