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
Handwritten implementation of IEnumerator to avoid allocations #1255
Conversation
f540d3d
to
e61ffbf
Compare
Thanks Yury for diving into this one! Did you by any chance run the Performance tests to see which overall perf impact it has on the codebase ? |
I created very simple benchmark:
There are four cases:
The result is the following: BenchmarkDotNet=v0.11.3, OS=Windows 10.0.15063.1387 (1703/CreatorsUpdate/Redstone2)
Intel Core i7-6700 CPU 3.40GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
Frequency=3328127 Hz, Resolution=300.4693 ns, Timer=TSC
[Host] : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3190.0
Clr : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3190.0
Job=Clr Runtime=Clr
The change fixes the allocation of enumerator and also speed up a bit the main case. PS Will run perfomance tests a bit later because it is time-consuming 😉 |
Nice 👍 - I don't recall us using any LINQ on immutable stacks, but with a regression there it's good to have an eye on it. Benchmark results would be great, just in case we're tripped up anywhere :-) |
Here are two benchmark results: the baseline(commit hash 5c3a782) and the PR. As far as I understand cases of the benchmark, the most relevant is net46BenchmarkDotNet=v0.10.6, OS=Windows 10 Redstone 2 (10.0.15063)
Processor=Intel Core i7-6700 CPU 3.40GHz (Skylake), ProcessorCount=8
Frequency=3328125 Hz, Resolution=300.4695 ns, Timer=TSC
[Host] : Clr 4.0.30319.42000, 32bit LegacyJIT-v4.7.3190.0
DefaultJob : Clr 4.0.30319.42000, 32bit LegacyJIT-v4.7.3190.0
netcoreapp2.0BenchmarkDotNet=v0.10.6, OS=Windows 10 Redstone 2 (10.0.15063)
Processor=Intel Core i7-6700 CPU 3.40GHz (Skylake), ProcessorCount=8
Frequency=3328125 Hz, Resolution=300.4695 ns, Timer=TSC
dotnet cli version=2.1.4
[Host] : .NET Core 4.6.26614.01, 64bit RyuJIT
DefaultJob : .NET Core 4.6.26614.01, 64bit RyuJIT
It seems there is no perfomance degradation 😅 PS Also here are full results. |
@nblumhardt Is it possible to include the PR to 2.8 release? |
LGTM! Let's give it a blast on Thanks @Pliner! I'd love to spend some more time looking at allocations like those |
Hi!
What issue does this PR address?
There are some allocations during an enumeration of
ImmutableStack
:The PR fixes them by introducing handwritten enumerator which is
struct
and most of the time will live on the stack and will not be boxed.Does this PR introduce a breaking change?
Nope
Please check if the PR fulfills these requirements
Other information: