runtime: iOS/Catalyst build performance regression from net8.0 to net9.0

Description

There’s quite a noticeable decrease in performance building iOS and Catalyst apps:

dotnet build -bl:../net8.0-ios.binlog
Restore complete (0.5s)
  MauiTestApp net8.0-ios succeeded (12.6s) → bin/Debug/net8.0-ios/iossimulator-arm64/MauiTestApp.dll

Build succeeded in 13.3s
dotnet build -bl:../net9.0-ios.binlog
Restore complete (0.4s)
  MauiTestApp net9.0-ios succeeded (17.4s) → bin/Debug/net9.0-ios/iossimulator-arm64/MauiTestApp.dll

Build succeeded in 18.1s

The performance regresson is also present for maccatalyst

Steps to Reproduce

The problem is reproducible with a MAUI template project, changing the TFM between net8.0-ios and net9.0-ios

Link to public reproduction project repository

No response

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.100 SR10

Affected platforms

iOS, macOS

Affected platform versions

No response

Did you find any workaround?

Roll back to dotnet 8

Relevant log output

net8.0-ios.binlog.txt net9.0-ios.binlog.txt

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 23 (12 by maintainers)

Most upvoted comments

Confirmed. Not only is the build regression fixed, the build is now faster than ever. Nice one, thanks!

dotnet build -bl:../net9.0-ios.binlog
Restore complete (0.5s)
  MauiTestApp net9.0-ios succeeded (6.0s) → bin/Debug/net9.0-ios/iossimulator-arm64/MauiTestApp.dll

Build succeeded in 6.6s

Heads up – we’ve gained a better understanding of the regression and are working on a fix: https://github.com/dotnet/runtime/issues/110833. I’ll let you know once we have a PR ready.

I suggest enabling dedup optimization in fullAOT mode only: xamarin/xamarin-macios#20687

That got changed here:

https://github.com/xamarin/xamarin-macios/pull/20936

with a follow up fix here:

https://github.com/xamarin/xamarin-macios/pull/20945

and a final fix here:

https://github.com/xamarin/xamarin-macios/pull/20953

so I’m a bit unsure as to exactly when it’s safe/correct to enable/disable dedup at this point.

That said, I have a tentative PR up to disable dedup if interpreting every assembly: https://github.com/xamarin/xamarin-macios/pull/21661.

The fix https://github.com/dotnet/runtime/pull/113316 has been included in the 9.0.4 servicing release.

@rolfbjarne That’s awesome, thanks. Maybe the conditions can be improved/tailored, but if it’s useful to anyone, I find the following gives a pretty decent productivity bump as a workaround until the above patch gets released.

<_IsDedupEnabled Condition="'$(Configuration)' == 'Debug'">false</_IsDedupEnabled>

Struggling with the same issue on quite big project. Can’t share binlog, however I will paste suspicious fragments from it:

.net8 MtouchLink=SdkOnly, Target _AOTCompile took 7:27:062

Mono Ahead of Time compiler - compiling assembly /Users/runner/work/1/s/.../obj/Release/net8.0-ios/ios-arm64/linked/aot-instances.dll
Adding 189341 dedup-ed methods.
Compiled: 204048/204067
Output file: 'obj/Release/net8.0-ios/ios-arm64/nativelibraries/aot-output/arm64/aot-instances.dll.s'.
Linking symbol: '_mono_aot_module_aot_instances_info'.
JIT time: 95567 ms, Generation time: 135788 ms, Assembly+Link time: 5 ms.

.net9 MtouchLink=SdkOnly, Target _AOTCompile took 49:06.155

Mono Ahead of Time compiler - compiling assembly /Users/runner/work/1/s/.../obj/Release/net9.0-ios/ios-arm64/linked/aot-instances.dll
AOTID D40720D9-E52C-B309-F30B-2764A328EE50
Adding 199729 dedup-ed methods.
Compiled: 217410/217439
Output file: 'obj/Release/net9.0-ios/ios-arm64/nativelibraries/aot-output/arm64/aot-instances.dll.s'.
Linking symbol: '_mono_aot_module_aot_instances_info'.
JIT time: 304743 ms, Generation time: 23051 ms, Assembly+Link time: 0 ms.

.net9 MtouchLink=Full, Target _AOTCompile took 1:48:586

Mono Ahead of Time compiler - compiling assembly /Users/runner/work/1/s/.../obj/Release/net9.0-ios/ios-arm64/linked/aot-instances.dll
AOTID B743CE1F-39E6-5F34-4B4F-D41CA695FBBC
Adding 36107 dedup-ed methods.
Compiled: 31572/31594
Output file: 'obj/Release/net9.0-ios/ios-arm64/nativelibraries/aot-output/arm64/aot-instances.dll.s'.
Linking symbol: '_mono_aot_module_aot_instances_info'.
JIT time: 13739 ms, Generation time: 4360 ms, Assembly+Link time: 0 ms.

Build time bloated a lot. Unfortunately the app is not ready to be fully linked, SdkOnly is the preferable option for us. Interpreter is turned off.

Fwiw, I got similar times on my m2 w/ what @rolfbjarne provided.

I’ve looked a bit into this, and this is what I’ve found so far:

  1. With the interpreter enabled, the compilation time is much slower because it takes much longer to compile the AOT-compiled aot-instances code. I’m guessing this is because there’s twice as much native code:
$ ls -lah /Users/rolf/test/dotnet/aotperf/TestApp/obj/Debug/net*.0-ios/iossimulator-arm64/nativelibraries/aot-output/arm64/aot-instances.dll.s
.rw-r--r--@  88,225,773 rolf 2024-12-04 18:01:48.832720614 +0100 obj/Debug/net8.0-ios/iossimulator-arm64/nativelibraries/aot-output/arm64/aot-instances.dll.s
.rw-r--r--@ 151,735,792 rolf 2024-12-04 18:02:08.333604974 +0100 obj/Debug/net9.0-ios/iossimulator-arm64/nativelibraries/aot-output/arm64/aot-instances.dll.s
  • .NET 8: 88 mb
  • .NET 9: 151 mb

The AOT compilation is also slower, but that shows up better in the next finding:

  1. With the interpreter disabled (/p:UseInterpreter=false), we AOT much more code, and since the AOT compiler is also much slower, it has a much bigger effect:

Timings for only the AOT compilation:

  • .NET 8: 33s
  • .NET 9: 1m23s

The resulting app bundle is also a bit bigger, but nothing that would explain the almost 3x difference in AOT compilation:

$ du -hs bin/Debug/net*.0-ios/iossimulator-arm64/TestApp-net*.0.app
397M	bin/Debug/net8.0-ios/iossimulator-arm64/TestApp-net8.0.app
420M	bin/Debug/net9.0-ios/iossimulator-arm64/TestApp-net9.0.app

So it seems this is a runtime issue, so moving there.

M2 …

SkiaSharpBug % dotnet build -bl:../net9.0-ios.binlog
Restore complete (0.6s)
  SkiaSharpSample net9.0-ios succeeded (24.4s) → bin/Debug/net9.0-ios/iossimulator-arm64/SkiaSharpSample.dll

Build succeeded in 25.3s

SkiaSharpBug % dotnet build -bl:../net8.0-ios.binlog
Restore complete (0.3s)
  SkiaSharpSample net8.0-ios succeeded (16.8s) → bin/Debug/net8.0-ios/iossimulator-arm64/SkiaSharpSample.dll

Build succeeded in 17.3s