-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
RyuJIT: Intrinsify GetType().TypeHandle.Value and typeof(T).TypeHandle.Value #5973
Comments
/cc @RussKeldorph |
@jkotas Would JIT be involved in this one? |
Yes, this would be JIT work. |
There are complications with array type handles and proxy type handles (for remoting on full framework) - the type handle is not equal to methodtable for these. It may be better to implement fixups for System.Type instead. It would avoid helper call to get to the System.Type. This optimization would be applicable more broadly, and it would make access to the raw handle value cheaper too. I have conversion about it with @cmckinsey @geoffkizer recently. |
@jkotas did you ever do any writeup for the fixup idea? |
Today, ldtoken is expanded to We can add a new method to JIT/EE interface |
Yesterday I've been working on improving the performance of
showed up in the profiles: It was just a few %, which itself is not bad. The problem was that this generic code is executed only for value types and having this extra call(s) ( |
I had two cases recently where I could use this. (managed I believe the issues with array type handles should not be a problem any more. |
Would this still be a problem for pointers and potentially function pointers? ( I think we could potentially do something cheap for our own internal purposes within CoreLib if instead of looking at the public API surface ( The intrinsic handling of Would that work? |
I do not think so. The issues with these are about boxing. There is no boxing involved here.
This intrisic seems to be doing the exact same thing as |
I looked into it but kind of got lost in it.
Optimizing GetValueInternal would be enough to help our internal use cases. The public use case that is the motivating example in the first post makes assumptions about the IntPtr that might not hold. Such dictionary would certainly not work in .NET Native as it shipped for UWP apps since the same type can have multiple of these undocumented IntPtr values in there (when compiled with the shared library). |
As a first pass experiment, I prototyped intrinsicifying [Benchmark]
[Arguments(2048)]
[Arguments(4096)]
[Arguments(8192)]
[Arguments(16384)]
public byte[] AllocArray(int len)
{
return GC.AllocateUninitializedArray<byte>(len);
}
The prototype commit isn't production-quality, but it gives a first-pass estimate of the potential savings. |
I report a problem. In a certain community in China, someone encountered that the file reading speed of C# is always slower than that of python. Including using new arrays, or using I'm not sure if this helps. This is the link to the problem. According to its description, the performance is only related to array allocation, and has nothing to do with the API used. When I suggested that he use memory file mapping to read, he said that he tried it, and the speed was also 0.6 seconds. There will be no improvement. This may indicate that when C# internally reads files, the default implementation of buffer allocation wastes 0.2 seconds. |
@sgf The impact of this issue on a single buffer allocation is in nanoseconds range. If you are seeing 0.2 seconds delta, the problem is something else. If you are able to reproduce the problem, please open a new issue on it, include details about the .NET and Python versions, OS and hardware. |
ok,tks |
I guess this issue can be closed after #85804 (CoreCLR and NativeAOT) |
Sometimes I use
IntPtr
instead ofType
as a key (or part of a complex key) inDictionary
.Advantages is that it is a value type so I don't keep full blown
Type
object alive, and GC likes value type fields more than ref ones because less references to follow.But each time I need to get the value or check if a key exists I have to get
Type
just to retrieve its handle value.I suggest intrinsifying these calls:
How
In the following code JIT just compares method table pointer in the object header to the address of method table of
String
type.It could do the same when getting type handle value :
category:cq
theme:type-intrinsics
skill-level:expert
cost:medium
The text was updated successfully, but these errors were encountered: