-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite Enum.HasFlags and Enum.Equals in C# #59514
Conversation
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
What is the performance hit on Mono side? I recall we moved this to native due to bad codegen but it was long time ago. |
The mono changes look ok. |
|
||
TEnum[] ret = new TEnum[ulValues.Length]; | ||
for (int i = 0; i < ulValues.Length; i++) | ||
ret[i] = (TEnum)ToObject(enumType, ulValues[i]); |
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.
We have the ToUInt64 generic helper that takes a ulong and produces a TEnum. Would it be worth adding the inverse and using it here to avoid roundtripping through a boxed object here? Or you don't think it's worthwhile since there's already the array allocation?
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.
The reason for this change is AOT friendliness. The non-generic GetValues method is not AOT friendly since it creates a new array type dynamically.
Yeah, I agree that this can be done in a better way. I am going to undo this change for this PR, and deal with it in next one.
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.
Just linking for reference:
#44355 (comment)
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.
Nice!
It is performance improvement for Mono. using System;
using System.Diagnostics;
class Test
{
static Enum e1 = StringSplitOptions.RemoveEmptyEntries;
static Enum e2 = StringSplitOptions.TrimEntries;
static void Main()
{
Stopwatch sw = new Stopwatch();
for (;;)
{
sw.Restart();
for (int i = 0; i < 100000000; i++)
e1.HasFlag(e2);
Console.WriteLine(sw.ElapsedMilliseconds);
}
}
} Windows x64 Baseline: ~2500ms per iteration (For reference, CoreCLR is around 530ms per iteration.) |
Same benchmark for Enum.Equals Windows x64 Mono: |
The failures are #59541 |
No description provided.