Skip to content
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

Investigate size increase for Android libmonosgen-2.0.so between net6.0 and 7.0 #68330

Closed
akoeplinger opened this issue Apr 21, 2022 · 2 comments · Fixed by #68354
Closed

Investigate size increase for Android libmonosgen-2.0.so between net6.0 and 7.0 #68330

akoeplinger opened this issue Apr 21, 2022 · 2 comments · Fixed by #68354

Comments

@akoeplinger
Copy link
Member

akoeplinger commented Apr 21, 2022

As noticed in dotnet/android#6598 (comment) we're seeing about a 1.5MB size increase for libmonosgen-2.0.so for 7.0.

According to bloaty most of the size increase is from the .text section:

$ bloaty  Microsoft.NETCore.App.Runtime.Mono.android-arm64.7.0.0-preview.5.22220.8/runtimes/android-arm64/native/libmonosgen-2.0.so -- Microsoft.NETCore.App.Runtime.Mono.android-arm64.6.0.4/runtimes/android-arm64/native/libmonosgen-2.0.so
    FILE SIZE        VM SIZE
 --------------  --------------
   +57% +1.28Mi   +57% +1.28Mi    .text
   +55%  +115Ki   +55%  +115Ki    .eh_frame
   +71% +35.9Ki   +71% +35.9Ki    .eh_frame_hdr
  [NEW] +6.98Ki  [NEW] +6.92Ki    .got.plt
   +18% +2.86Ki   +18% +2.86Ki    .data
   +19% +2.00Ki   +20% +2.00Ki    .hash
  +3.6%    +744  +3.6%    +744    .rela.plt

One theory is that the NDK version is the culprit, we used r21b in 6.0 and in 7.0 we use r23b. @grendello is taking a look at that.

@ghost
Copy link

ghost commented Apr 21, 2022

Tagging subscribers to 'arch-android': @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Issue Details

As noticed in dotnet/android#6598 (comment) we're seeing about a 1.5MB size increase for libmonosgen-2.0.so for 7.0.

According to bloaty most of the size increase is from the .text section:

$ bloaty  Microsoft.NETCore.App.Runtime.Mono.android-arm64.7.0.0-preview.5.22220.8/runtimes/android-arm64/native/libmonosgen-2.0.so -- Microsoft.NETCore.App.Runtime.Mono.android-arm64.6.0.4/runtimes/android-arm64/native/libmonosgen-2.0.so
    FILE SIZE        VM SIZE
 --------------  --------------
   +57% +1.28Mi   +57% +1.28Mi    .text
   +55%  +115Ki   +55%  +115Ki    .eh_frame
   +71% +35.9Ki   +71% +35.9Ki    .eh_frame_hdr
  [NEW] +6.98Ki  [NEW] +6.92Ki    .got.plt
   +18% +2.86Ki   +18% +2.86Ki    .data
   +19% +2.00Ki   +20% +2.00Ki    .hash
  +3.6%    +744  +3.6%    +744    .rela.plt

One theory is that the NDK version is the culprit, we used r21b in 6.0 and in 7.0 we use r23b. @grendello is taking a look at that.

Author: akoeplinger
Assignees: -
Labels:

os-android, area-Build-mono

Milestone: 7.0.0

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Apr 21, 2022
@akoeplinger akoeplinger removed the untriaged New issue has not been triaged by the area owner label Apr 21, 2022
@akoeplinger
Copy link
Member Author

akoeplinger commented Apr 21, 2022

This turned out to be the cmake version, the current cmake version 3.17 we use prints this warning:

  CMake Warning at /usr/local/android-ndk/build/cmake/android-legacy.toolchain.cmake:416 (message):
    An old version of CMake is being used that cannot automatically detect
    compiler attributes.  Compiler identification is being bypassed.  Some
    values may be wrong or missing.  Update to CMake 3.19 or newer to use
    CMake's built-in compiler identification.
  Call Stack (most recent call first):
    /usr/local/android-ndk/build/cmake/android.toolchain.cmake:55 (include)
    /usr/local/share/cmake-3.17/Modules/CMakeDetermineSystem.cmake:93 (include)
    CMakeLists.txt:7 (project)

After updating to the latest cmake 3.23.1 the size is back to the expected one and the warning is gone.

akoeplinger added a commit to akoeplinger/dotnet-buildtools-prereqs-docker that referenced this issue Apr 21, 2022
cmake 3.17 doesn't work well with newer Android NDK and results in increased binary size, see dotnet/runtime#68330
akoeplinger added a commit to dotnet/dotnet-buildtools-prereqs-docker that referenced this issue Apr 21, 2022
cmake 3.17 doesn't work well with newer Android NDK and results in increased binary size, see dotnet/runtime#68330
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Apr 21, 2022
jonpryor pushed a commit to dotnet/android that referenced this issue May 5, 2022
Context: dotnet/runtime#56989
Context: dotnet/runtime#68734
Context: dotnet/runtime#68914
Context: dotnet/runtime#68701

Changes: dotnet/installer@04e40fa...c7afae6

	% git diff --shortstat 04e40fa9...c7afae69
	 98 files changed, 1788 insertions(+), 1191 deletions(-)

Changes: dotnet/runtime@a21b9a2...c5d40c9

	% git diff --shortstat a21b9a2d...c5d40c9e
	 28347 files changed, 1609359 insertions(+), 1066473 deletions(-)

Changes: dotnet/linker@01c4f59...04c49c9

	% git diff --shortstat 01c4f590...04c49c9d
	 577 files changed, 28039 insertions(+), 10835 deletions(-)

Updates to build with the .NET 7 SDK and use the runtime specified by
the SDK.  We no longer use different SDK & runtime versions.

This produces a 7.0.100 Android workload.

After this is merged we should be able to enable Maestro to consume
future .NET 7 builds from dotnet/installer/main.

~~ Known Issues ~~

AOT+LLVM crashes on startup:

  * dotnet/runtime#68914

Xamarin.Build.Download hits a breaking change with `ZipEntry`:

  * dotnet/runtime#68734
  * xamarin/XamarinComponents#1368

illink outputs different MVIDs per architecture:

  * dotnet/linker#2203
  * dotnet/runtime#67660

Size of `libmonosgen-2.0.so` regressed:

  * dotnet/runtime#68330
  * dotnet/runtime#68354

Newer .NET 7 builds crash on startup:

  * dotnet/runtime#68701
  * This is worked around by *disabling* lazy loading of AOT'd
    assemblies 6dc426f.
  * TODO: re-enable once we get a fixed .NET 7 runtime.

TODO: We can't yet push to the `dotnet7` feed. Working on this.

Co-authored-by: Jonathan Peppers <jonathan.peppers@microsoft.com>
Co-authored-by: Peter Collins <pecolli@microsoft.com>
akoeplinger added a commit to akoeplinger/runtime that referenced this issue Jun 30, 2022
Brings in new cmake 2.23.1 and Android NDK 23c.

Set the optimization level to O2 to fix size/perf regression.

Fixes dotnet#68330
akoeplinger added a commit that referenced this issue Jun 30, 2022
Brings in new cmake 2.23.1 and Android NDK23c which fixes an issue with the binary size and perf of libmonosgen-2.0.so

In NDK23b they decided to no longer pass -O2 compiler optimization flag (for arm64, armv7 used -Oz) as part of the Android toolchain but delegate to upstream CMake behavior: https://github.com/android/ndk/wiki/Changelog-r23 and android/ndk#1536

CMake defaults to -O3 for Release builds but unfortunately this causes quite a noticable binary size increase and perf regression.

The Xamarin Android team measured startup time on an average of 10 runs of `dotnet new maui` on a Pixel 5:
```
-O3: 893.7ms
-O2: 600.2ms
-Oz: 649.1ms
```

We now explicitly pass in -O2 for Android builds.

Fixes #68330
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jun 30, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant