-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Streamline default EqualityComparer and Comparer for Enums #21604
Conversation
cc @marek-safar |
Just a nitpick but |
@Suchiman Thanks for taking a look |
src/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simpler and faster is a nice combination :)
Fabulous! Is breaking serialization compatibility between 2.x and master concern? |
This shouldn't break compatibility because of the SetType that's used. @ViktorHofer can confirm, but I believe we have tests for this specifically. |
Right, but how do you hit it if the type to deserialize is e.g. UInt64EnumComparer ? |
A serialization payload will never contain the type |
This borrows the implementation strategy for these from CoreRT. It makes it both simpler (fewer types and lines of code) and faster in some cases since we always use the exact right underlying type. E.g. The following micro-benchmark is 25% faster with this change: ``` enum MyEnum : byte { x, y }; var comparer = Comparer<MyEnum>.Default; for (int i = 0; i < 100000000; i++) { comparer.Compare(MyEnum.x, MyEnum.y); comparer.Compare(MyEnum.y, MyEnum.x); } ``` Undo accidental change CR feedback
…reclr#21604) This borrows the implementation strategy for these from CoreRT. It makes it both simpler (fewer types and lines of code) and faster in some cases since we always use the exact right underlying type. E.g. The following micro-benchmark is 25% faster with this change: ``` enum MyEnum : byte { x, y }; var comparer = Comparer<MyEnum>.Default; for (int i = 0; i < 100000000; i++) { comparer.Compare(MyEnum.x, MyEnum.y); comparer.Compare(MyEnum.y, MyEnum.x); } ``` Commit migrated from dotnet/coreclr@82e02f3
This borrows the implementation strategy for these from CoreRT. It makes it both simpler (fewer types and lines of code) and faster in some cases since we always use the exact right underlying type.
E.g. The following micro-benchmark is 25% faster with this change: