u/GOPbIHbI4in r/dotnet • Recommends
Zero cost delegates in .NET 10
The delegates are essentially the glorified callbacks, and historically the JIT was not been able to do the right thing to reduce the cost of using them.
This has changed in .NET 10 with de-abstraction initiative.
De-abstraction had two main focuses: de-abstracting the interface calls (which led to huge performance gains on stuff like enumeration over lists via IEnumerable interface), and de-abstracting the delegates.
When the JIT sees that the delegate doesn’t escape it can stack allocate it. Which means that in some cases the LINQ operation that was allocating 64 bytes now would have 0 allocations (this is the case when the lambda captures only the instan…