You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Simplify OptimizeGeneratedCodeHandler to speed up trimming #11477
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
IsDirectBinding is not a global constant. The value can be different for each NSObject subclass. In some cases (like if we know there's no subclasses for the type) this can be optimized. Otherwise the check must remain.
get_DynamicRegistrationSupported
Remove completely, linker propagates the value already
This value is true for the original, compile code. However if/when we can remove the dynamic registrar (and drop a lot of code by doing so) then IIRC its updated to return false.
The value can be different for each NSObject subclass. In some cases (like if we know there's no subclasses for the type) this can be optimized.
For those which you know it can be constant, you register the method with Annotations.SetAction (method, MethodAction. ConvertToStub) and set the value via Annotations.SetStubValue (method, 1)
However if/when we can remove the dynamic registrar
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
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 Annotations.SetAction (method, MethodAction. ConvertToStub) and set the value via Annotations.SetStubValue (method, 1)
I might be missing something obvious here but which method are you talking about in your code snippet ?
Example: Let's say that NSData.Foo and NSString.Bar have calls to the IsDirectBinding property.
By analyzing the app we know that
NSMutableData is used and that it subclass NSData so we cannot optimize/remove the call to IsDirectBinding;
NSString has no subclass (used by the app) so it does not need to call IsDirectBinding
So what's the method to be used ?
it can't be NSData.Foo as it can not be optimized (would break the subclasses);
NSString.Bar as it can be optimized ? but how does it know it's IsDirectBinding that can be optimized (and other other properties inside the method) ?
NSObject.IsDirectBinding property ? it cannot be since optimizing this into NSObject would also apply to NSData ?
I might be missing something obvious here but which method are you talking about in your code snippet ?
This will probably need a different approach than I thought. Based on your description it sounds that IsDirectBinding is another version of typeof (Foo) != GetType () comparison, right? If that's the case I believe the IL Linker will be able to understand that condition soon.
IsDirectBinding: has to stay, too complex to use a feature switch
DynamicRegistrationSupported: already converted to feature switch (bf5e35a)
BlockLiteral.SetupBlock[Unsafe]: has to stay, too complex for a feature switch, and can't use a source generator because we have to work with existing binaries (NuGets).
BlockLiteral.ctor: has to stay, too complex for a feature switch, and can't use a source generator because we have to work with existing binaries (NuGets).
IsARM64CallingConvention: convert to feature switch
Activity
spouliot commentedon May 7, 2021
Binary breaking change.
yes, that's was my plan.
spouliot commentedon May 7, 2021
Can you explain how that works ?
IsDirectBindingis not a global constant. The value can be different for eachNSObjectsubclass. In some cases (like if we know there's no subclasses for the type) this can be optimized. Otherwise the check must remain.spouliot commentedon May 7, 2021
This value is
truefor the original, compile code. However if/when we can remove the dynamic registrar (and drop a lot of code by doing so) then IIRC its updated to returnfalse.spouliot commentedon May 7, 2021
The (Xamarin.iOS) managed code has to call different p/invoke signatures based on the ABI.
marek-safar commentedon May 7, 2021
For those which you know it can be constant, you register the method with
Annotations.SetAction (method, MethodAction. ConvertToStub)and set the value viaAnnotations.SetStubValue (method, 1)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 https://github.com/xamarin/xamarin-macios/blob/2b7dc07d20fc06344d7f164af8934f5e755572c2/src/ObjCRuntime/Runtime.cs#L1833 and if we add feature switch for Arch linker will automatically evaluate the method as constant returning.
spouliot commentedon May 7, 2021
I might be missing something obvious here but which
methodare you talking about in your code snippet ?Example: Let's say that
NSData.FooandNSString.Barhave calls to theIsDirectBindingproperty.By analyzing the app we know that
NSMutableDatais used and that it subclassNSDataso we cannot optimize/remove the call toIsDirectBinding;NSStringhas no subclass (used by the app) so it does not need to callIsDirectBindingSo what's the
methodto be used ?NSData.Fooas it can not be optimized (would break the subclasses);NSString.Baras it can be optimized ? but how does it know it'sIsDirectBindingthat can be optimized (and other other properties inside the method) ?NSObject.IsDirectBindingproperty ? it cannot be since optimizing this intoNSObjectwould also apply toNSData?spouliot commentedon May 7, 2021
The easy/initial (not exhaustive) candidates for substitutions I identified are
[1] #10457
[2] #9613
[3] can be overridden (legacy) with optional arguments
[4] were not removed by legacy linker
marek-safar commentedon May 7, 2021
You could consider guarding some of them under the existing
System.Diagnostics.Debugger.IsSupportedfeature switch which is unset for Release build.marek-safar commentedon May 10, 2021
This will probably need a different approach than I thought. Based on your description it sounds that IsDirectBinding is another version of
typeof (Foo) != GetType ()comparison, right? If that's the case I believe the IL Linker will be able to understand that condition soon.[dotnet][linker] Fix the elimitation of calls for `UIApplication::Ens…
[dotnet][linker] Fix the elimitation of calls for `UIApplication::Ens…
7 remaining items
rolfbjarne commentedon Jul 15, 2026
I had a look with the current state of the steps:
rolfbjarne commentedon Aug 6, 2026
All we can do is done now.