-
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
Make typeof(T).IsValueType more efficient #12248
Comments
Why it needs to be this complex? Can't it be just |
Counter part of |
@jkotas Well yes, you could use something like |
@jkotas As an aside, it looks like the implementation could be changed in Comparer/EqualityComparer to make detecting nullables more efficient... see EqualityComparer and Comparer |
So the real problem is that
Micro-optimizations in these methods are not interesting. These methods are executed just once; and micro-optimizations won't change how expensive they are. |
How complicated would it be to teach the JIT to recognize existing code as intrinsic? I remember seeing an issue raised by @omariom in coreclr that was dated 2015 about recognizing these kinds of patterns; can't find it now, but I came over it a year later and it was still open. |
Add new CorInfoIntrinsics enum in inc\corinfo.h; recognize on the VM side; expand it impIntrinsic in the JIT. For example, here is a change that added new intrinsics for |
Make JIT time constants from calls to Type methods and properties |
Seems like what this issue is about is to make the existing check more efficient, so changing title to match that plus adding the label of enhancement. |
I was hoping typeof(T).IsValueType would get evaluated during JIT compilation which would allow for dead code elimination, but alas: https://github.com/dotnet/corefx/issues/16217
I was hoping typeof(T).IsValueType would get evaluated during JIT compilation which would allow for dead code elimination, but alas: https://github.com/dotnet/corefx/issues/16217
I was hoping typeof(T).IsValueType would get evaluated during JIT compilation which would allow for dead code elimination, but alas: https://github.com/dotnet/corefx/issues/16217
I was hoping typeof(T).IsValueType would get evaluated during JIT compilation which would allow for dead code elimination, but alas: https://github.com/dotnet/corefx/issues/16217
I was hoping typeof(T).IsValueType would get evaluated during JIT compilation which would allow for dead code elimination, but alas: https://github.com/dotnet/corefx/issues/16217
I was hoping typeof(T).IsValueType would get evaluated during JIT compilation which would allow for dead code elimination, but alas: https://github.com/dotnet/corefx/issues/16217
It would be nice to have a cost-free API to check whether a generic type is a class. You can check
default(T) != null
and be 100% confident something is a struct if that condition is true, but ifdefault(T) == null
then it could be a class or a nullable. The only way to tell right now is via reflection, using something liketypeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(Nullable<>)
.I did want to use such an API several times in the past, although I can't recall where. One scenario I can think of though is if you want to treat
T
as an object ifT
is a class, but avoid boxing for structs.Does this sound like a good idea?
Moved from https://github.com/dotnet/corefx/issues/16209
/cc @benaadams @jkotas
The text was updated successfully, but these errors were encountered: