Change our code to use Class.GetHandleIntrinsic instead of Class.GetHandle whenever possible:
Some kind of optimization step during app build time is probably needed, because whether the Class.GetHandle -> Class.GetHandleIntrinsic transformation is safe or not partial depends on build settings (in particular the deployment target).
Modify the generator to emit Class.GetHandleIntrinsic when safe to do so (when the class in question is available in all OS versions we support).
Modify our manual code as well.
Add a (cecil?) test to verify that we got the above changes right (and we don't introduce regressions in the future).
Many years ago we added a
Class.GetHandleIntrinsic
method to speed up fetching class handles:https://github.com/xamarin/xamarin-macios/blob/209de6f29755c66a80ac3c01961b8f7390886e69/src/ObjCRuntime/Class.cs#L141-L149
However, the comment is incorrect / out-of-date, because the AOT-compiler side of the code is not there anymore.
The idea would be to:
Class.GetHandleIntrinsic
to do what the comment says. Mono's AOT compiler already does something similar for Selector.GetHandle: https://github.com/dotnet/runtime/blob/87a35d6bf48fb418bf53630cd346781b349148f3/src/mono/mono/mini/intrinsics.c#L2221-L2261, which can be used as a starting point (the implementation would be different though - the generated native code should be equivalent to the Objective-C code[ObjectiveCType class]
.Class.GetHandleIntrinsic
instead ofClass.GetHandle
whenever possible:Class.GetHandle
->Class.GetHandleIntrinsic
transformation is safe or not partial depends on build settings (in particular the deployment target).Class.GetHandleIntrinsic
when safe to do so (when the class in question is available in all OS versions we support).