-
Notifications
You must be signed in to change notification settings - Fork 564
[illink] Don't initialize managed peer #5444
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
[illink] Don't initialize managed peer #5444
Conversation
Context: dotnet/android#5400 Context: dotnet/android#5444 Don't call `ManagedPeer.Init()` from the `JniRuntime` constructor when `XA_JI_EXCLUDE` is `#define`d. The presence of `ManagedPeer.Init()` requires that *all* Xamarin.Android apps contain `System.Linq.Expressions` types after linking, because `ManagedPeer.Construct()` calls `JniEnvironment.Runtime.MarshalMemberBuilder.CreateConstructActivationPeerFunc()` which pulls in all the `System.Linq.Expressions` infrastructure. Currently, *nothing* requires `ManagedPeer` *at all*; Java.Interop- "style" "Java Activation" (8c83f64) is not used outside of unit tests. Consequently, there is no need to pay the cost of System.Linq.Expressions within all Xamarin.Android apps. Wrap the `ManagedPeer.Init()` invocation with `XA_JI_EXCLUDE` so that the Xamarin.Android build of `Java.Interop.dll` (893562c) *excludes* the `ManagedPeer.Init()` invocation. This allows every Xamarin.Android app to link out System.Linq.Expressions, unless the app is otherwise using that namespace. `XA_JI_EXCLUDE` is intended to be set by `$(JavaInteropDefineConstants)` MSBUild property within the optional file `bin/Build$(Configuration)/XAConfig.props`, which the xamarin-android build will create before building `Java.Interop.csproj`. Cleanup the `src/Java.Interop` source code to remove use of the `XA_INTEGRATION` symbol. This symbol is no longer of use, and now only adds noise.
d28a78c to
fa92b24
Compare
20c1bb8 to
095fc6e
Compare
Context: dotnet#5400 Context: dotnet/java-interop#761 Generate `XAConfig.props` file in Java.Interop to define `XA_JI_EXCLUDE` compilation constant. The generated file contains properties set for Java.Interop by XA. So far it is only setting one property, and thus doesn't necessarily be generated. I still wanted to be written by `xaprep`, plus it might be handy in future for other configuration. The currently set `JavaInteropDefineConstants` property is going to be used to disable `ManagedPeer` initialization. We don't really use `ManagedPeer` today and it is duplicating functionality of `ConstructorBuilder` class. The unwanted effect of having it in JI is that it is pulling in System.Linq.Expressions, which greatly increase assemblies size after linking. The size reduction for simple XA app is cca 135kbytes of compressed size. Size difference in bytes ([*1] apk1 only, [*2] apk2 only): - 27 assemblies/Mono.Android.dll - 30 assemblies/System.Collections.Concurrent.dll - 989 assemblies/System.Linq.dll - 2,930 assemblies/Java.Interop.dll - 4,514 assemblies/System.Collections.dll *1 - 4,874 assemblies/System.ObjectModel.dll *1 - 7,987 assemblies/System.Private.CoreLib.dll - 115,284 assemblies/System.Linq.Expressions.dll *1 Summary: - 136,635 Assemblies -14.87% (of 918,689) - 139,506 Package size difference -1.79% (of 7,780,819)
095fc6e to
a04ba26
Compare
|
Current This happens because commit 130905e added the Java.Interop unit tests to the Mono.Android-Tests app, and the Java.Interop unit tests do use There are thus two paths forward:
I'm of course partial to (2). How do we remove the
namespace Java.Interop {
partial class JniRuntime {
partial abstract class JniValueManager {
public abstract void ActivatePeer (JniObjectReference reference, ConstructorInfo peerConstructor, object[]? constructorArgumentValues);
}
}
}Within the Java.Interop repo,
Once JniEnvironment.Runtime.ValueManager.ActivatePeer (new JniObjectReference (n_self), ctor, pvalues);This should allow |
Context: #5444 This allows us to remove SLE dependency and save cca 15% of assembly size. Size difference of BuildReleaseArm64False on net6: Size difference in bytes ([*1] apk1 only, [*2] apk2 only): + 96 assemblies/Mono.Android.dll - 331 assemblies/System.Collections.Concurrent.dll - 907 assemblies/Java.Interop.dll - 1,003 assemblies/System.Linq.dll - 3,856 assemblies/System.ObjectModel.dll *1 - 4,496 assemblies/System.Collections.dll *1 - 7,824 assemblies/System.Private.CoreLib.dll - 115,284 assemblies/System.Linq.Expressions.dll *1 Summary: - 133,605 Assemblies -15.33% (of 871,776)
|
Superseded by #5530 |
Context: dotnet#5444 This allows us to remove SLE dependency and save cca 15% of assembly size. Size difference of BuildReleaseArm64False on net6: Size difference in bytes ([*1] apk1 only, [*2] apk2 only): + 96 assemblies/Mono.Android.dll - 331 assemblies/System.Collections.Concurrent.dll - 907 assemblies/Java.Interop.dll - 1,003 assemblies/System.Linq.dll - 3,856 assemblies/System.ObjectModel.dll *1 - 4,496 assemblies/System.Collections.dll *1 - 7,824 assemblies/System.Private.CoreLib.dll - 115,284 assemblies/System.Linq.Expressions.dll *1 Summary: - 133,605 Assemblies -15.33% (of 871,776)
Context: #5400
Context: dotnet/java-interop#761
Generate
XAConfig.propsfile in Java.Interop to defineXA_JI_EXCLUDEcompilation constant.
The generated file contains properties set for Java.Interop by XA. So
far it is only setting one property, and thus doesn't necessarily be
generated. I still wanted to be written by
xaprep, plus it might behandy in future for other configuration.
The currently set
JavaInteropDefineConstantsproperty is usedto disable
ManagedPeerinitialization.We don't really use
ManagedPeertoday and it is duplicatingfunctionality of
ConstructorBuilderclass. The unwanted effect ofhaving it in JI is that it is pulling in
System.Linq.Expressions, whichgreatly increase assemblies size after linking.
The size reduction for simple XA app is cca 135kbytes of compressed
size.