-
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
Moving fast parts of cast FCALLs to managed code. #1068
Conversation
63cb4c5
to
9ca0b1b
Compare
} | ||
|
||
// NOTE!! | ||
// This is a copy of C++ implementation in CastCache.cpp |
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.
More likely castcache.h
. #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.
Nit: The implementation is in the .cpp file, but the VM filename is in lower case (castcache.cpp). #Resolved
@tommcdon - tried the "logical unwind" here in the last change. Does not seem to be sufficient. |
Proposed fix at a lower level is here: VSadov@d269b62. Tested the fix in VS and it seems to work correctly. #Resolved |
0d03012
to
f0a5986
Compare
ff792a3
to
0729321
Compare
5d743cc
to
a0223a9
Compare
I think this is ready to be reviewed. #Resolved |
The change moves fast parts of casting helpers to managed code and removes various existing implementations - in C++, in asm in C/inlined asm. Now it is all C#. #Resolved |
I also hoped to not have specialized versions for class and interface casts. Tuns out outperforming hand-tuned assembly is challenging, so specialized methods are still there. Whoever wrote the AMD64 assembly helpers did a god job. I have discussed with @davidwrighton possible ways of speeding up the cache lookup:
This may improve the cache lookup enough to switch Interface and/or Class case to Any or maybe it will not. I think perf tinkering should be a separate change though. |
src/coreclr/src/inc/corinfo.h
Outdated
@@ -423,12 +423,10 @@ enum CorInfoHelpFunc | |||
// the right helper to use | |||
|
|||
CORINFO_HELP_ISINSTANCEOFINTERFACE, // Optimized helper for interfaces | |||
CORINFO_HELP_ISINSTANCEOFARRAY, // Optimized helper for arrays |
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.
I would keep these for now, even if it means that the implementation is same. #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.
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.
I just could not see what could be done differently in a helper if we knew we are casting to an array.
For identity cast check we could now just compare MTs, which we do for any cast...
In reply to: 368261248 [](ancestors = 368261248,368260447)
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.
I am guessing JIT could inline identity cast check similarly to class cast. Not sure if those are common with arrays but with classes inlining identity cast helps a lot.
In reply to: 368261350 [](ancestors = 368261350,368261248,368260447)
Here is what I see on a microbenchmark that calls in a loop a method that performs a particular kind of cast
where the baseline is
#Resolved |
...clr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs
Outdated
Show resolved
Hide resolved
The Linux is similar, but there are few interesting differences. Since we did not use hand-written assembly on Linux and C++ helpers were not as sophisticated, there is some gain in specialized methods. On the other hand the improvements in cache lookup seems to have been negated by something. We even see a 1-2% regression. I think it is acceptable, but wonder why we have it. Either we have some platform specific penalty for moving to managed (call conventions, access of statics?), or GCC produces better code (compared to MSVC) for native cache lookup and JIT is not matching that. ===== baseline
=== after the change:
|
Note - all the measurements have some degree of noise. |
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/CastHelpers.cs
Outdated
Show resolved
Hide resolved
Also renamed `BaseMethodTable` to `ParentMethodTable` - to match native code closer.
Missed an attribute in one place
Removed |
Thanks!! |
I do not see ChkCastAny JITed during startup. For the record, here is the list of methods that I see getting JITed during startup (CoreLib R2R, empty
What is the list of methods that you see JITed during startup? |
:mips-interest |
JIT_IsInstanceOfAny
andJIT_ChkCastAny
to managed code as the first ones to move.JIT_IsInstanceOfInterface
Fixes:https://github.com/dotnet/coreclr/issues/27931