C# performance – Staxel https://blog.playstaxel.com Thu, 23 Sep 2021 08:55:35 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.6 IEquatable https://blog.playstaxel.com/iequatable/ Sat, 05 Apr 2014 18:51:33 +0000 http://bartwe.net/?p=14 I was profiling when i noticed a large number of allocations of a type i recognized to be a struct.

This was surprising because  structs are value types and so not normally heap allocated unless some autoboxing happens, so after a bit of digging it turned out that by default, if you use a struct as a key in a Dictionary it gets boxed for equality operations.

Implementing IEquatable quickly fixed this issue.

]]>