Skip to content

[One .NET] use AssemblyMetadataAttribute for IsTrimmable #5879

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

Merged

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Apr 27, 2021

Fixes: #5638

Going forward in .NET 6, we shouldn't use the %(IsTrimmable)
metadata anymore, but use the following C# attribute in each assembly
instead:

[assembly: AssemblyMetadata ("IsTrimmable", "True")]

Similar changes on the iOS side here:

dotnet/macios@289053b

Bump to xamarin/java.interop/main@df4c5e7c

Changes: dotnet/java-interop@f9faaab...df4c5e7

This adds AssemblyMetadataAttribute for Java.Interop.dll.

@jonathanpeppers jonathanpeppers force-pushed the runtime-pack-assemblies-trimmable branch from b8eb4ea to 8de059f Compare April 27, 2021 21:21
@jonathanpeppers
Copy link
Member Author

It appears that this change, causes many of the assemblies' sizes to increase:

Size difference in bytes ([*1] apk1 only, [*2] apk2 only):

188,703 assemblies/System.Net.Http.dll *2
142,573 assemblies/System.Private.Xml.dll *2
122,051 assemblies/System.Private.CoreLib.dll
 58,699 assemblies/System.Net.Security.dll *2
 58,248 assemblies/System.Security.Cryptography.X509Certificates.dll *2
 57,566 assemblies/System.Linq.Expressions.dll *2
 56,809 assemblies/System.Net.Sockets.dll *2
 52,297 assemblies/System.Text.RegularExpressions.dll *2
 44,316 assemblies/Mono.Android.dll
 42,052 assemblies/System.Net.Primitives.dll *2
 40,247 assemblies/System.Private.Uri.dll *2
 35,298 assemblies/Mono.Android.Export.dll *2
 28,176 assemblies/System.Formats.Asn1.dll *2
 26,943 assemblies/Java.Interop.dll
 25,938 assemblies/System.Security.Cryptography.Algorithms.dll *2
 19,205 assemblies/System.Runtime.Numerics.dll *2
 18,864 assemblies/System.IO.Compression.dll *2
 18,053 assemblies/System.Net.NetworkInformation.dll *2
 14,365 assemblies/System.Security.Cryptography.Encoding.dll *2
 13,934 assemblies/System.Threading.Channels.dll *2
 11,791 assemblies/System.IO.Compression.Brotli.dll *2
 11,347 assemblies/System.Collections.Concurrent.dll *2
 10,637 assemblies/System.Net.NameResolution.dll *2
  9,646 assemblies/System.Collections.NonGeneric.dll *2
  9,602 assemblies/System.Collections.dll *2
  7,538 assemblies/System.IO.FileSystem.dll *2
  5,786 assemblies/System.Security.Cryptography.Primitives.dll *2
  5,692 assemblies/System.Threading.dll *2
  5,020 assemblies/System.ObjectModel.dll *2
  3,760 assemblies/Microsoft.Win32.Primitives.dll *2
  3,283 assemblies/System.Runtime.InteropServices.dll *2
  3,089 assemblies/System.Runtime.InteropServices.RuntimeInformation.dll *2
  2,416 assemblies/System.Console.dll *2
  2,391 assemblies/System.Runtime.Extensions.dll *2
  2,306 assemblies/System.Reflection.Emit.dll *2
  2,284 assemblies/System.Reflection.Emit.ILGeneration.dll *2
  2,258 assemblies/System.Diagnostics.Debug.dll *2
  2,249 assemblies/System.Reflection.Emit.Lightweight.dll *2
  2,240 assemblies/System.Reflection.Primitives.dll *2
  2,212 assemblies/System.Threading.Thread.dll *2
  2,178 assemblies/System.Xml.ReaderWriter.dll *2
  1,619 assemblies/System.Runtime.dll
  1,487 assemblies/System.Runtime.CompilerServices.Unsafe.dll *2
  1,412 assemblies/System.Linq.dll
      5 assemblies/UnnamedProject.dll

Summary:
1,176,575 Assemblies 175.17% (of 671,690)

@sbomer is that expected? This might be one reason why iOS is larger than Android right now, they have this change already: dotnet/macios@289053b

@sbomer
Copy link
Member

sbomer commented Apr 27, 2021

Nope, that's definitely not expected. Any chance you could share the linker command-line or a binlog?

@spouliot
Copy link

This might be one reason why iOS is larger than Android right now, they have this change already: dotnet/macios@289053b

No, this did not cause larger apps, nor any additional assemblies to be bundled. AFAICT it was a no op.

FWIW our apps were already larger before that recent commit :|

@jonathanpeppers
Copy link
Member Author

@sbomer here is the log from that failing test above: msbuild.zip

Maybe the [assembly: AssemblyMetadata ("IsTrimmable", "True")] is somehow not in the assemblies I expect, checking on that.

@jonathanpeppers jonathanpeppers force-pushed the runtime-pack-assemblies-trimmable branch from 8de059f to 8c1c87a Compare April 28, 2021 22:00
@jonathanpeppers
Copy link
Member Author

Ok, there is another Mono.Android.Export.dll that I added the attribute. Let's check if this fares any better.

@jonathanpeppers
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jonathanpeppers
Copy link
Member Author

I think we're good here now, it was Mono.Android.Export.dll.

I'll need to land changes in java.interop first, then we can go about merging this.

jonathanpeppers added a commit to dotnet/java-interop that referenced this pull request Apr 29, 2021
Context: dotnet/android#5638
Context: dotnet/android#5879

Going forward in .NET 6, we shouldn't use the `%(IsTrimmable)`
metadata anymore, but use the following C# attribute in each assembly
instead:

    [assembly: AssemblyMetadata ("IsTrimmable", "True")]

Similar changes on the iOS side here:

dotnet/macios@289053b

This adds `AssemblyMetadataAttribute` for `Java.Interop.dll`.
jonpryor pushed a commit to dotnet/java-interop that referenced this pull request Apr 29, 2021
Context: dotnet/android#5638
Context: dotnet/android#5879

Going forward in .NET 6, we shouldn't use the `%(IsTrimmable)`
metadata anymore, but instead use the following C# attribute in
each assembly for which linking/"trimming" is supported:

	[assembly: AssemblyMetadata ("IsTrimmable", "True")]

Similar changes on the iOS side here:

  * dotnet/macios@289053b

Add `AssemblyMetadataAttribute` to `Java.Interop.dll`.
Fixes: dotnet#5638

Going forward in .NET 6, we shouldn't use the `%(IsTrimmable)`
metadata anymore, but use the following C# attribute in each assembly
instead:

    [assembly: AssemblyMetadata ("IsTrimmable", "True")]

Similar changes on the iOS side here:

dotnet/macios@289053b

Bump to xamarin/java.interop/main@df4c5e7c

Changes: dotnet/java-interop@f9faaab...df4c5e7

This adds `AssemblyMetadataAttribute` for `Java.Interop.dll`.
@jonathanpeppers jonathanpeppers force-pushed the runtime-pack-assemblies-trimmable branch from 8c1c87a to 09295de Compare April 30, 2021 02:26
@jonathanpeppers jonathanpeppers marked this pull request as ready for review April 30, 2021 02:27
@jonathanpeppers
Copy link
Member Author

The two test failures seem to be unrelated:

error XA0010: Could not retrieve the Android ABI for the attached device or emulator. Please reconnect the device or restart the emulator, and try again.

@jonathanpeppers jonathanpeppers merged commit c60635b into dotnet:main Apr 30, 2021
@jonathanpeppers jonathanpeppers deleted the runtime-pack-assemblies-trimmable branch April 30, 2021 19:17
jonathanpeppers added a commit that referenced this pull request Apr 30, 2021
Fixes: #5638

Going forward in .NET 6, we shouldn't use the `%(IsTrimmable)`
metadata anymore, but use the following C# attribute in each assembly
instead:

    [assembly: AssemblyMetadata ("IsTrimmable", "True")]

Similar changes on the iOS side here:

dotnet/macios@289053b

Bump to xamarin/java.interop/main@df4c5e7c

Changes: dotnet/java-interop@f9faaab...df4c5e7

This adds `AssemblyMetadataAttribute` for `Java.Interop.dll`.
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mark all Android runtime pack assemblies as trimmable
4 participants