3 ms·
Well, yes, but delegates as a term is not often used in other languages so I did not mention them for simplicity's sake. For what it's worth - the real issue i
by neonsunset 2y ago
Well, yes, but delegates as a term is not often used in other languages so I did not mention them for simplicity's sake.
For what it's worth - the real issue in C# is not even the virtual calls but the way Roslyn caches lazily allocated non-capturing lambda instances. It does so in a compiler-unfriendly way due to questionable design decisions inside Roslyn.
Luckily, this has a high chance of changing in .NET 10. Ideally, by the time it releases hopefully the compiler will both understand the Roslyn's pattern of caching better and be able to stack-allocate non-escaping lambda closure instances.
Lambdas capturing 'this' inside instance methods of the object they refer to do not allocate either.