dotnet / dotnet/macios

.NET: SingleView app size

Open
#10,249 90 comments 0 reactions 0 assignees View on GitHub
dotnet enhancement iOS macOS
Dominant language
C#
Stars
2.9k
Forks
576
Avg merge
2d 13h
Merged PRs (30d)
96

Description

App sizes are currently significantly bigger with .NET 6 with a very simple hello world app.

# Test case

* Checkout `xamarin-macios`
* Execute:

```shell
cd tests/dotnet
make compare
```

This will build a very simple hello world app for both .NET 6 and the old-style Xamarin.iOS and generate a report in markdown format. This can be pasted into the issue (e.g. for each preview) so the progress can be tracked.

## Known Issues

* [x] [The (dynamic) registrar isn't removed when enabling all the optimizations](https://github.com/xamarin/xamarin-macios/issues/10512)
* The dynamic registrar requires a larger subset of `System.Reflection` API (see [below](https://github.com/xamarin/xamarin-macios/issues/10249#issuecomment-797158484))
* [x] The .NET 6 version does not strip the native executable.
* [x] The [mono-cil-strip](https://github.com/xamarin/xamarin-macios/issues/11445) tool is not run on the final assemblies (it's not available without the mono SDK installed)
* All assemblies still have their IL even when it's not required (FullAOT by default for device builds)
* Tracked, among other tools, in https://github.com/dotnet/runtime/issues/35852 @marek-safar recently mentioned it was being looked at for Blazor (there might be another issue I missed)

# Historical

## App sizes

### Xamarin.iOS

du -hs size-comparison/MySingleView/oldnet/bin/iPhone/Release/MySingleView.app
4.4M size-comparison/MySingleView/oldnet/bin/iPhone/Release/MySingleView.app

### .NET 6

du -hs size-comparison/MySingleView/dotnet/bin/iPhone/Release/net6.0-ios/ios-arm64/*.app
27M size-comparison/MySingleView/dotnet/bin/iPhone/Release/net6.0-ios/ios-arm64/MySingleView.app

## Assembly sizes

### Xamarin.iOS

ls -lahS size-comparison/MySingleView/oldnet/bin/iPhone/Release/MySingleView.app/*.dll size-comparison/MySingleView/oldnet/bin/iPhone/Release/MySingleView.app/*.exe
-rw-r--r-- 1 rolf wheel 397K Dec 9 19:04 size-comparison/MySingleView/oldnet/bin/iPhone/Release/MySingleView.app/mscorlib.dll
-rw-r--r-- 1 rolf wheel 54K Dec 9 19:04 size-comparison/MySingleView/oldnet/bin/iPhone/Release/MySingleView.app/Xamarin.iOS.dll
-rw-r--r-- 1 rolf wheel 4.5K Dec 9 19:04 size-comparison/MySingleView/oldnet/bin/iPhone/Release/MySingleView.app/MySingleView.exe
-rw-r--r-- 1 rolf wheel 4.5K Dec 9 19:05 size-comparison/MySingleView/oldnet/bin/iPhone/Release/MySingleView.app/System.dll

### .NET 6

ls -lahS size-comparison/MySingleView/dotnet/bin/iPhone/Release/net6.0-ios/ios-arm64/*.app/*.dll
-rw-r--r-- 1 rolf wheel 1.3M Dec 9 19:05 size-comparison/MySingleView/dotnet/bin/iPhone/Release/net6.0-ios/ios-arm64/MySingleView.app/System.Private.CoreLib.dll
-rw-r--r-- 1 rolf wheel 161K Dec 9 19:05 size-comparison/MySingleView/dotnet/bin/iPhone/Release/net6.0-ios/ios-arm64/MySingleView.app/Xamarin.iOS.dll
-rw-r--r-- 1 rolf wheel 17K Dec 9 19:05 size-comparison/MySingleView/dotnet/bin/iPhone/Release/net6.0-ios/ios-arm64/MySingleView.app/System.Runtime.dll
-rw-r--r-- 1 rolf wheel 16K Dec 9 19:05 size-comparison/MySingleView/dotnet/bin/iPhone/Release/net6.0-ios/ios-arm64/MySingleView.app/System.Runtime.Serialization.Formatters.dll
-rw-r--r-- 1 rolf wheel 5.0K Dec 9 19:05 size-comparison/MySingleView/dotnet/bin/iPhone/Release/net6.0-ios/ios-arm64/MySingleView.app/MySingleView.dll

---

There are multiple issues here:

* [x] ~The .NET 6 version has unnecessary dylibs (because it's linking libraries statically).~ [fix](https://github.com/xamarin/xamarin-macios/issues/11145)
* [x] ~The .NET 6 version does not strip the native executable.~
* [ ] The .NET 6 version's assemblies are much bigger (the linker doesn't remove as much): 1,5 MB vs 460 KB.

Additionally the .NET 6 version takes twice as long to compile (22s vs 11s on my machine), but that's a different issue (filed as https://github.com/xamarin/xamarin-macios/issues/10251).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.