xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.48k stars 518 forks source link

Building an empty net9.0-ios project on MacOS targetting iOS Simulator takes a long time #21643

Closed mlancione closed 2 days ago

mlancione commented 4 days ago

Apple platform

iOS

Framework version

net9.0-*

Affected platform version

Terminal or VS Code on MacOS 14.7

Description

Building the template net9.0-ios project via "dotnet new ios" for the iOS Simulator takes 74.6s to build (on an M2 MacBook). It spends over 60s in the _AOTCompile step.

Steps to Reproduce

  1. dotnet new ios
  2. dotnet build (or "dotnet build -p:Configuration=Debug -p:TargetFramework=net9.0-ios -p:RuntimeIdentifier=iossimulator-arm64 -p:MtouchDebug=true" via VS Code)

I have tried setting the following properties but nothing seems to affect the AOTCompile step:

<TrimMode>copy</TrimMode> or <TrimMode>partial</TrimMode>
<PublishAot>false</PublishAot>
<NativeAOT>false</NativeAOT>
<LinkMode>None</LinkMode> or <LinkMode>SdkOnly</LinkMode>

XCode installed: 16.0

Workloads:

Installed Workload Id Manifest Version Installation Source

android 35.0.7/9.0.100 SDK 9.0.100
ios 18.0.9617/9.0.100 SDK 9.0.100
maccatalyst 18.0.9617/9.0.100 SDK 9.0.100
macos 15.0.9617/9.0.100 SDK 9.0.100
maui 9.0.0/9.0.100 SDK 9.0.100
maui-android 9.0.0/9.0.100 SDK 9.0.100
maui-ios 9.0.0/9.0.100 SDK 9.0.100
maui-maccatalyst 9.0.0/9.0.100 SDK 9.0.100

Did you find any workaround?

Setting UseInterpreter to true drops the build time down to 16.5s however this debugger bug prevents us from using this workaround: https://github.com/xamarin/xamarin-macios/issues/8731 https://github.com/mono/mono/issues/19899

Build logs

msbuild.binlog.zip

rolfbjarne commented 2 days ago

There are two main possibilities to decrease build time:

  1. Enable the trimmer (set TrimMode=partial in the project file)
  2. Enable the interpreter (set UseInterpreter=true in the project file).

I see the interpreter is not an option for you, but I'm surprised setting TrimMode=partial doesn't change anything. Can you get an MSBuild binlog with that property set?

mlancione commented 2 days ago

I retried TrimMode=partial and it indeed worked. The build time for the template iOS project is now 11s. Should TrimMode=copy or MtouchLink=None also speed up build time since they're supposed to bypass all trimming? Those options seem to still cause the build to take 70+ seconds.

Building my main Application project is still taking 70+ seconds with the TrimMode=partial setting.

Can I email you a binlog directly for this project to see why the TrimMode=partial setting seems to be ignored? I would rather not post it here.

rolfbjarne commented 2 days ago

Should TrimMode=copy or MtouchLink=None also speed up build time since they're supposed to bypass all trimming? Those options seem to still cause the build to take 70+ seconds.

No, that won't speed up the build, because while it won't spend any time trimming, it'll spend a lot of time AOT-compiling all the assemblies (because they weren't trimmed, there's a lot of code to AOT-compile).

Can I email you a binlog directly for this project to see why the TrimMode=partial setting seems to be ignored? I would rather not post it here.

Yes, of course: Rolf.Kvinge@microsoft.com

mlancione commented 2 days ago

Should TrimMode=copy or MtouchLink=None also speed up build time since they're supposed to bypass all trimming? Those options seem to still cause the build to take 70+ seconds.

No, that won't speed up the build, because while it won't spend any time trimming, it'll spend a lot of time AOT-compiling all the assemblies (because they weren't trimmed, there's a lot of code to AOT-compile).

Thanks for the explanation. Is there a way to bypass both the trimming and the AOT compile (for iOS simulator builds) while keeping UseInterpreter set to false?

Can I email you a binlog directly for this project to see why the TrimMode=partial setting seems to be ignored? I would rather not post it here.

Yes, of course: Rolf.Kvinge@microsoft.com

Thanks. The binlog has been sent.

rolfbjarne commented 2 days ago

Can I email you a binlog directly for this project to see why the TrimMode=partial setting seems to be ignored? I would rather not post it here.

Yes, of course: Rolf.Kvinge@microsoft.com

Thanks. The binlog has been sent.

The TrimMode=partial option is working, it's just that your project is so much bigger than a new project from a template that the AOT compiler takes so much longer to compile everything.

Using TrimMode=full might help somewhat, but the real improvement is probably going to come from using the interpreter instead, once the debugger issue is fixed (thanks for the test case!)

rolfbjarne commented 2 days ago

Closing as a duplicate of #21444, where we'll deal with improving build times for arm64 simulators.