- Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
We made the public HashCode.Combine method so that developers would use it any time combining is necessary in their own hash code computations. But we use it internally in very few of our own GetHashCode methods, instead preferring to use either the internal HashHelpers.Combine:
https://github.com/dotnet/coreclr/blob/456afea9fbe721e57986a21eb3b4bb1c9c7e4c56/src/System.Private.CoreLib/shared/System/Numerics/Hashing/HashHelpers.cs#L11-L17
or using a custom combine that's generally something as simple as an xor. HashCode.Combine is 3-4x slower than HashHelpers.Combine in today use, e.g. if used in ValueTuple.GetHashCode.
We should either determine that the extra benefits of HashCode.Combine are "worth it" and use it everywhere instead of HashHelpers.Combine, or we should fix HashCode.Combine's perf (likely at the expense of those "benefits") so that it becomes usable. At the moment if we're not comfortable using it ourselves, it's unclear how we could promote it for others to use.