Skip to content

iOS application size increase when migrating from legacy xamarin-ios to .net #19381

@rotanov

Description

@rotanov

Description

Context: Migrating game engine written in c# from legacy xamarin ios to .NET7.

After the migration, when comparing minimal engine project for ios ("EmptyProject") I noticed non neglectable increase in size of application (.NET7: 13.3MB , .NET8 10.8MB)

I built the project with legacy xamarin ios, net7 and net8 and tried to make some analysis and comparison. See Details section. Attachment contains built applications, debug symbols, MachO symbol dumps, some stats, binlogs, see Attachment section.

I understand there are a lot of issues on the matter and some growth is to be expected.
But 10Mb (for net8) seems like too much, may be I made some mistakes, or there are methods to reduce application size I'm not aware of? (apart from TrimSafe on engine assembly)

Details

Main object of interest is predicted download size, since that is by what appstore limits availability of download over metered connections. .app/.ipa size is not helpful in that regard, because afaik executable gets encrypted by appstore, making it compression-resistant. We predict download size as uncompressed executable size + everything else in ipa/app compressed size.

SDK legacy-xamarin-ios net7.0-ios net8.0-ios
executable size 23083888 35026384 32599520
executable growth factor x1 x1.51 x1.41
executable growth diff 0 11942496 9515632
rest of the app 8265323 12979960 12168123
rest of the app compressed 4257091 5617476 5588735
predicted app download size 27340979 40643860 38188255
download size growth factor x1 x1.48 x1.39
download size growth diff 0 13302881 10847276

bloaty was used to generate symbols:

bloaty -d segments,sections,symbols,compileunits --debug-file=./bin/Release/EmptyProject.app.dSYM/Contents/Resources/DWARF/EmptyProject ./bin/Release/EmptyProject.app/EmptyProject -n 0 --tsv > symbols.txt

I used slightly modified (included in attachment) script by @ivanpovazan to generate stats. (mentioned here) Generated stats are also in attachment.

Script modifications are:

  1. introduced category, where I tried to couple together everything I think engine and game project are responsible for.
  2. categorized more symbols as CORLIB
  3. 2. broke the diff, so diff is disabled

Even so, the "OTHERS" section grew a lot.

Stats:

legacy xamarin ios
--------------------------------------------------------------------------------
Stats for symbols from __TEXT,__text: 
--------------------------------------------------------------------------------
Total number of _infos:                                    0
Total number of plts:                                  35625
Total number of wrappers:                               3155
Total number of icus:                                      0
Total number of Globalizations:                         1496
Total number of generics:                              10383
--------------------------------------------------------------------------------
Total size of _infos:                                      0
Total size of plts:                                   712672
Total size of wrappers:                               606384
Total size of icus:                                        0
Total size of Globalizations:                         290856
Total size of generics:                              2400912
--------------------------------------------------------------------------------
Total symbols:                                        102682
        Total corelib:                                         16840    16.40%
        Total sysios:                                           2504     2.44%
        Total mono:                                             7023     6.84%
        Total others:                                          26769    26.07%
        Total game and engine:                                 49546    48.25%
Total size:                                         19778536
        Total corelib:                                       3716896    18.79%
        Total sysios:                                         337796     1.71%
        Total mono:                                          3117024    15.76%
        Total others:                                        2240916    11.33%
        Total game and engine:                              10365904    52.41%
--------------------------------------------------------------------------------

net7
--------------------------------------------------------------------------------
Stats for symbols from __TEXT,__text: 
--------------------------------------------------------------------------------
Total number of _infos:                                    0
Total number of plts:                                  34430
Total number of wrappers:                               4171
Total number of icus:                                   5648
Total number of Globalizations:                         1904
Total number of generics:                              19493
--------------------------------------------------------------------------------
Total size of _infos:                                      0
Total size of plts:                                   688912
Total size of wrappers:                              1049952
Total size of icus:                                   872852
Total size of Globalizations:                         382336
Total size of generics:                              5410680
--------------------------------------------------------------------------------
Total symbols:                                        142057
        Total corelib:                                         37509    26.40%
        Total sysios:                                           3032     2.13%
        Total mono:                                             6696     4.71%
        Total others:                                          43358    30.52%
        Total game and engine:                                 51462    36.23%
Total size:                                         30762632
        Total corelib:                                       9797056    31.85%
        Total sysios:                                         528448     1.72%
        Total mono:                                          4327068    14.07%
        Total others:                                        4056944    13.19%
        Total game and engine:                              12053116    39.18%
--------------------------------------------------------------------------------
net8
--------------------------------------------------------------------------------
Stats for symbols from __TEXT,__text: 
--------------------------------------------------------------------------------
Total number of _infos:                                    0
Total number of plts:                                      1
Total number of wrappers:                               3604
Total number of icus:                                   5621
Total number of Globalizations:                         1323
Total number of generics:                              10026
--------------------------------------------------------------------------------
Total size of _infos:                                      0
Total size of plts:                                      140
Total size of wrappers:                               861976
Total size of icus:                                   872424
Total size of Globalizations:                         533484
Total size of generics:                              3182648
--------------------------------------------------------------------------------
Total symbols:                                        103924
        Total corelib:                                         34695    33.38%
        Total sysios:                                           2618     2.52%
        Total mono:                                             6379     6.14%
        Total others:                                          30602    29.45%
        Total game and engine:                                 29630    28.51%
Total size:                                         27785504
        Total corelib:                                       9430576    33.94%
        Total sysios:                                         414288     1.49%
        Total mono:                                          3943104    14.19%
        Total others:                                        4024752    14.49%
        Total game and engine:                               9972784    35.89%
--------------------------------------------------------------------------------

MachO sections comparison:

macho-sections-comparison

Environment

  • macOS Sonoma 14.0, intel CPU
  • XCode 15.0
Version information
Visual Studio Community 2022 for Mac
Version 17.6.6 (build 408)
Installation UUID: 7571e8bb-d341-4541-a456-2451824e8830

Runtime
.NET 7.0.3 (64-bit)
Architecture: X64
Microsoft.macOS.Sdk 13.1.1007; git-rev-head:8afca776a0a96613dfb7200e0917bb57f9ed5583; git-branch:release/7.0.1xx-xcode14.2

Roslyn (Language Service)
5.6.0-3.23180.6+99e956e42697a6dd886d1e12478ea2b27cceacfa

NuGet
Version: 6.4.0.117

Xamarin Designer
Version: 17.6.3.9
Hash: 2648399ae8
Branch: remotes/origin/d17-6
Build date: 2023-10-23 17:40:07 UTC

.NET SDK (x64)
SDK: /usr/local/share/dotnet/sdk/7.0.403/Sdks
SDK Version: 7.0.403
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks

.NET Runtime (x64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Version: 7.0.13

Xamarin.Profiler
Version: 1.8.0.49
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Xamarin.Android
Not Installed

Microsoft Build of OpenJDK
Java SDK: Not Found

Eclipse Temurin JDK
Java SDK: Not Found

Android SDK Manager
Version: 17.6.0.50
Hash: a715dca
Branch: HEAD
Build date: 2023-10-23 17:40:12 UTC

Android Device Manager
Version: 0.0.0.1309
Hash: 06e3e77
Branch: HEAD
Build date: 2023-10-23 17:40:12 UTC

Apple Developer Tools
Xcode: 15.0 22265
Build: 15A240d

Xamarin.Mac
Version: 9.3.0.18 Visual Studio Community
Hash: 9d266025e
Branch: xcode14.3
Build date: 2023-09-06 19:52:26-0400

Xamarin.iOS
Version: 16.4.0.18 Visual Studio Community
Hash: 9d266025e
Branch: xcode14.3
Build date: 2023-09-06 19:52:27-0400

Build Information
Release ID: 1706060408
Git revision: 3912eca6712af97335aa3a782abaa75ff86ec74a
Build date: 2023-10-23 17:38:20+00
Build branch: release-17.6
Build lane: release-17.6

Operating System
Mac OS X 14.0.0
Darwin 23.0.0 Darwin Kernel Version 23.0.0
    Fri Sep 15 14:42:42 PDT 2023
    root:xnu-10002.1.13~1/RELEASE_X86_64 x86_64

Attachment

I'm sorry for the attachment format, max upload size is 20MB and there's extension whitelist.

  1. Download all the parts of the archive
  2. Swap .00x and .zip in the name of each file
  3. Extract. (I used 7zip-gui for windows to pack and split)

net-ios-app-size-analysis.001.zip
net-ios-app-size-analysis.002.zip
net-ios-app-size-analysis.003.zip
net-ios-app-size-analysis.004.zip
net-ios-app-size-analysis.005.zip

.
│   calc_stats.bat -- runs stats.py in each of top level directories starting with _
│   stats.py -- modified script
│   summary.md
├───legacy-xamarin-ios
│   │   symbols.txt -- symbols made using bloaty
│   │   symbols_*.list -- symbols filtered by stats.py
│   │   symbols_stats.list -- stats made by stats.py
│   │   msbuild.binlog -- binlog
│   │   
│   ├───EmptyProject.app -- the application
│   └───EmptyProject.app.dSYM -- debug symbols
│                               
├───net7.0-ios -- same structure                         
├───net8.0-ios -- same structure
│                           
├───_legacy-vs-net7 -- this and below are directories for running stats.py in (empty, since I commented out diff calculation in stats.py)
├───_legacy-vs-net8
├───_net7-vs-net8
└───macho-sections-comparison.png

Metadata

Metadata

Assignees

No one assigned

    Labels

    app-sizeenhancementThe issue or pull request is an enhancement

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions