MahApps.Metro.IconPacks icon indicating copy to clipboard operation
MahApps.Metro.IconPacks copied to clipboard

Remove delegate allocation

Open kronic opened this issue 4 years ago • 6 comments

kronic avatar Jun 23 '21 14:06 kronic

@kronic Can you explain the benefit of these changes?

punker76 avatar Jun 23 '21 20:06 punker76

@punker76 there will be no allocation for the delegate when called.

kronic avatar Jun 23 '21 20:06 kronic

@kronic I never saw such a suggestion, also if I look to the official doc. So if you have any information about htis then please show me. Thx

punker76 avatar Jun 24 '21 14:06 punker76

@punker76 https://sharplab.io/#gist:bdaac746f37bcd9bba8436ffeb1e81e4

kronic avatar Aug 17 '21 11:08 kronic

https://devblogs.microsoft.com/dotnet/understanding-the-cost-of-csharp-delegates/

kronic avatar Aug 18 '21 19:08 kronic

@kronic Could you elaborate a bit more on what your changes achieve exactly? The value stored in the static metadata should be the same as before. Your changes would reduce allocations if the delegate would be created multiple times, but in case of property metadata this is not the case. As shown in your SharpLab example your changes lead to increased code size and an additional backing field which stores the reference to the delegate. So instead of only storing the delegate instance in the property metadata we now would store it twice, once in the metadata and once in the backing field.

batzen avatar Aug 21 '21 16:08 batzen