Skip to content
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

Implement Class.GetHandleIntrinsic #21442

Open
rolfbjarne opened this issue Oct 15, 2024 · 0 comments
Open

Implement Class.GetHandleIntrinsic #21442

rolfbjarne opened this issue Oct 15, 2024 · 0 comments
Assignees
Labels
performance If an issue or pull request is related to performance
Milestone

Comments

@rolfbjarne
Copy link
Member

rolfbjarne commented Oct 15, 2024

Many years ago we added a Class.GetHandleIntrinsic method to speed up fetching class handles:

// This method is treated as an intrinsic operation by
// the aot compiler, generating a static reference to the
// class (it will be faster than GetHandle, but it will
// not compile unless the class in question actually exists
// as an ObjectiveC class in the binary).
public static NativeHandle GetHandleIntrinsic (string name)
{
return objc_getClass (name);
}

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:

  1. Add support in the AOT compiler for 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].
  2. Change our code to use Class.GetHandleIntrinsic instead of Class.GetHandle whenever possible:
    1. 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).
    2. 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).
    3. Modify our manual code as well.
    4. Add a (cecil?) test to verify that we got the above changes right (and we don't introduce regressions in the future).
@rolfbjarne rolfbjarne added the performance If an issue or pull request is related to performance label Oct 15, 2024
@rolfbjarne rolfbjarne added this to the .NET 10 milestone Oct 15, 2024
@mcumming mcumming self-assigned this Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance If an issue or pull request is related to performance
Projects
None yet
Development

No branches or pull requests

2 participants