-
Notifications
You must be signed in to change notification settings - Fork 517
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
Simplify OptimizeGeneratedCodeHandler to speed up trimming #11477
Comments
Binary breaking change.
yes, that's was my plan. |
Can you explain how that works ?
|
This value is |
The (Xamarin.iOS) managed code has to call different p/invoke signatures based on the ABI. |
For those which you know it can be constant, you register the method with
It was not clear to me if this should be configurable in net6 if so you keep it as it and add feature switch on top of it
Right but it's already constant xamarin-macios/src/ObjCRuntime/Runtime.cs Line 1833 in 2b7dc07
|
I might be missing something obvious here but which Example: Let's say that By analyzing the app we know that
So what's the
|
The easy/initial (not exhaustive) candidates for substitutions I identified are
[1] #10457 |
You could consider guarding some of them under the existing |
This will probably need a different approach than I thought. Based on your description it sounds that IsDirectBinding is another version of |
…ureUIThread` Lack of `MONOTOUCH` define in the dotnet csproj [1] made this look for the AppKit (XM) version. [1] defining `MONOTOUCH` would have required several more changes. Simplicity won! | Size | MySingleView.app | | ----------:|------------------| | 4,579,985 | legacy | | 10,787,541 | dotnet [before](https://gist.github.com/02e072567595088522f376e522e22899) | | 10,786,829 | dotnet [after](https://gist.github.com/afa5b7d4f9bb281646f050257034be11) | There are other ways to achieve this with ILLink [2] but again: Simplicity (by re-using) won! [2] xamarin#11477 --- a.cs 2021-05-12 14:17:13.000000000 -0400 +++ b.cs 2021-05-12 14:17:17.000000000 -0400 @@ -3764,13 +3764,6 @@ } namespace UIKit { - public class UIKitThreadAccessException : Exception - { - public UIKitThreadAccessException() - : base("UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.") - { - } - } [Register("UIApplication", true)] public class UIApplication : UIResponder { @@ -3824,14 +3817,6 @@ UIApplicationMain(args.Length, args, principal, @DeleGate); } - public static void EnsureUIThread() - { - if (CheckForIllegalCrossThreadCalls && mainThread != null && mainThread != Thread.CurrentThread) - { - throw new UIKitThreadAccessException(); - } - } - protected internal UIApplication(IntPtr handle) : base(handle) { @@ -3862,7 +3847,6 @@ public UIButton(CGRect frame) : base(NSObjectFlag.Empty) { - UIApplication.EnsureUIThread(); if (base.IsDirectBinding) { InitializeHandle(Messaging.IntPtr_objc_msgSend_CGRect(base.Handle, Selector.GetHandle("initWithFrame:"), frame), "initWithFrame:"); @@ -3876,7 +3860,6 @@ [Export("setTitle:forState:")] public virtual void SetTitle(string title, UIControlState forState) { - UIApplication.EnsureUIThread(); IntPtr arg = NSString.CreateNative(title); if (base.IsDirectBinding) { @@ -3948,8 +3931,7 @@ [Export("bounds")] get { - //Discarded unreachable code: IL_002f - UIApplication.EnsureUIThread(); + //Discarded unreachable code: IL_002b if (base.IsDirectBinding) { _ = 8; @@ -3965,7 +3947,6 @@ [Export("mainScreen")] get { - UIApplication.EnsureUIThread(); return Runtime.GetNSObject<UIScreen>(Messaging.IntPtr_objc_msgSend(class_ptr, Selector.GetHandle("mainScreen"))); } } @@ -4025,7 +4006,6 @@ [Export("addSubview:")] public virtual void AddSubview(UIView view) { - UIApplication.EnsureUIThread(); IntPtr nonNullHandle = NativeObjectExtensions.GetNonNullHandle(view, "view"); if (base.IsDirectBinding) { @@ -4065,7 +4045,6 @@ [Export("view", ArgumentSemantic.Retain)] get { - UIApplication.EnsureUIThread(); if (base.IsDirectBinding) { return Runtime.GetNSObject<UIView>(Messaging.IntPtr_objc_msgSend(base.Handle, Selector.GetHandle("view"))); @@ -4083,7 +4062,6 @@ public UIViewController() : base(NSObjectFlag.Empty) { - UIApplication.EnsureUIThread(); if (base.IsDirectBinding) { InitializeHandle(Messaging.IntPtr_objc_msgSend(base.Handle, Selector.GetHandle("init")), "init"); @@ -4124,7 +4102,6 @@ [Export("setRootViewController:", ArgumentSemantic.Retain)] set { - UIApplication.EnsureUIThread(); IntPtr arg = NativeObjectExtensions.GetHandle(value); if (base.IsDirectBinding) { @@ -4146,7 +4123,6 @@ public UIWindow(CGRect frame) : base(NSObjectFlag.Empty) { - UIApplication.EnsureUIThread(); if (base.IsDirectBinding) { InitializeHandle(Messaging.IntPtr_objc_msgSend_CGRect(base.Handle, Selector.GetHandle("initWithFrame:"), frame), "initWithFrame:"); @@ -4160,7 +4136,6 @@ [Export("makeKeyAndVisible")] public virtual void MakeKeyAndVisible() { - UIApplication.EnsureUIThread(); if (base.IsDirectBinding) { Messaging.void_objc_msgSend(base.Handle, Selector.GetHandle("makeKeyAndVisible")); @@ -4188,7 +4163,6 @@ public UIApplicationDelegate() : base(NSObjectFlag.Empty) { - UIApplication.EnsureUIThread(); base.IsDirectBinding = false; InitializeHandle(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, Selector.GetHandle("init")), "init"); } ```
…ureUIThread` (#11523) Lack of `MONOTOUCH` define in the dotnet csproj [1] made this look for the AppKit (XM) version. [1] defining `MONOTOUCH` would have required several more changes. Simplicity won! | Size | MySingleView.app | | ----------:|------------------| | 4,579,985 | legacy | | 10,787,541 | dotnet [before](https://gist.github.com/02e072567595088522f376e522e22899) | | 10,786,829 | dotnet [after](https://gist.github.com/afa5b7d4f9bb281646f050257034be11) | There are other ways to achieve this with ILLink [2] but again: Simplicity (by re-using) won! [2] #11477 --- a.cs 2021-05-12 14:17:13.000000000 -0400 +++ b.cs 2021-05-12 14:17:17.000000000 -0400 @@ -3764,13 +3764,6 @@ } namespace UIKit { - public class UIKitThreadAccessException : Exception - { - public UIKitThreadAccessException() - : base("UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.") - { - } - } [Register("UIApplication", true)] public class UIApplication : UIResponder { @@ -3824,14 +3817,6 @@ UIApplicationMain(args.Length, args, principal, @DeleGate); } - public static void EnsureUIThread() - { - if (CheckForIllegalCrossThreadCalls && mainThread != null && mainThread != Thread.CurrentThread) - { - throw new UIKitThreadAccessException(); - } - } - protected internal UIApplication(IntPtr handle) : base(handle) { @@ -3862,7 +3847,6 @@ public UIButton(CGRect frame) : base(NSObjectFlag.Empty) { - UIApplication.EnsureUIThread(); if (base.IsDirectBinding) { InitializeHandle(Messaging.IntPtr_objc_msgSend_CGRect(base.Handle, Selector.GetHandle("initWithFrame:"), frame), "initWithFrame:"); @@ -3876,7 +3860,6 @@ [Export("setTitle:forState:")] public virtual void SetTitle(string title, UIControlState forState) { - UIApplication.EnsureUIThread(); IntPtr arg = NSString.CreateNative(title); if (base.IsDirectBinding) { @@ -3948,8 +3931,7 @@ [Export("bounds")] get { - //Discarded unreachable code: IL_002f - UIApplication.EnsureUIThread(); + //Discarded unreachable code: IL_002b if (base.IsDirectBinding) { _ = 8; @@ -3965,7 +3947,6 @@ [Export("mainScreen")] get { - UIApplication.EnsureUIThread(); return Runtime.GetNSObject<UIScreen>(Messaging.IntPtr_objc_msgSend(class_ptr, Selector.GetHandle("mainScreen"))); } } @@ -4025,7 +4006,6 @@ [Export("addSubview:")] public virtual void AddSubview(UIView view) { - UIApplication.EnsureUIThread(); IntPtr nonNullHandle = NativeObjectExtensions.GetNonNullHandle(view, "view"); if (base.IsDirectBinding) { @@ -4065,7 +4045,6 @@ [Export("view", ArgumentSemantic.Retain)] get { - UIApplication.EnsureUIThread(); if (base.IsDirectBinding) { return Runtime.GetNSObject<UIView>(Messaging.IntPtr_objc_msgSend(base.Handle, Selector.GetHandle("view"))); @@ -4083,7 +4062,6 @@ public UIViewController() : base(NSObjectFlag.Empty) { - UIApplication.EnsureUIThread(); if (base.IsDirectBinding) { InitializeHandle(Messaging.IntPtr_objc_msgSend(base.Handle, Selector.GetHandle("init")), "init"); @@ -4124,7 +4102,6 @@ [Export("setRootViewController:", ArgumentSemantic.Retain)] set { - UIApplication.EnsureUIThread(); IntPtr arg = NativeObjectExtensions.GetHandle(value); if (base.IsDirectBinding) { @@ -4146,7 +4123,6 @@ public UIWindow(CGRect frame) : base(NSObjectFlag.Empty) { - UIApplication.EnsureUIThread(); if (base.IsDirectBinding) { InitializeHandle(Messaging.IntPtr_objc_msgSend_CGRect(base.Handle, Selector.GetHandle("initWithFrame:"), frame), "initWithFrame:"); @@ -4160,7 +4136,6 @@ [Export("makeKeyAndVisible")] public virtual void MakeKeyAndVisible() { - UIApplication.EnsureUIThread(); if (base.IsDirectBinding) { Messaging.void_objc_msgSend(base.Handle, Selector.GetHandle("makeKeyAndVisible")); @@ -4188,7 +4163,6 @@ public UIApplicationDelegate() : base(NSObjectFlag.Empty) { - UIApplication.EnsureUIThread(); base.IsDirectBinding = false; InitializeHandle(Messaging.IntPtr_objc_msgSendSuper(base.SuperHandle, Selector.GetHandle("init")), "init"); } ``` Co-authored-by: Sebastien Pouliot <sebastien.pouliot@microsoft.com>
Existing OptimizeGeneratedCodeHandler logic duplicates a lot of processing and logic which is done as part of core IL linker steps. The code can be significantly simplified if migrated to use .NET6 features.
A proposal about how this can be done for each of the optimizations
ProcessCalls
EnsureUIThread
Convert field into property returning constant or add feature switch to set the value.
get_Size
Remove completely as it's done by linker by default.
get_IsDirectBinding
Set the constant via https://github.com/mono/linker/blob/main/src/linker/ref/Linker/Annotations.cs#L27-L28 for any override which should return true/false
get_DynamicRegistrationSupported
Remove completely, linker propagates the value already
SetupBlock and SetupBlockUnsafe
This would be much better done with source generator and can probably stay for now as it has nothing to do with linker.
ProcessLoadStaticField
IsARM64CallingConvention
I'm not sure why it's needed as field if we build arm64 specific runtime pack.
Arch
Should be a feature switch with which substitutes field
The text was updated successfully, but these errors were encountered: