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

LinkAssembliesNoShrink is expensive #8421

Open
Youssef1313 opened this issue Oct 13, 2023 · 10 comments
Open

LinkAssembliesNoShrink is expensive #8421

Youssef1313 opened this issue Oct 13, 2023 · 10 comments
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. bug Component does not function as intended.
Milestone

Comments

@Youssef1313
Copy link
Member

Android application type

.NET Android (net7.0-android, etc.)

Affected platform version

Android 33.0.46

Description

image

This is very very slow.

Steps to Reproduce

Build the app in unoplatform/Uno.Samples#584

Did you find any workaround?

No response

Relevant log output

No response

@Youssef1313 Youssef1313 added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels Oct 13, 2023
@dellis1972 dellis1972 removed the needs-triage Issues that need to be assigned. label Oct 13, 2023
@dellis1972 dellis1972 added this to the .NET 9 Planning milestone Oct 13, 2023
@dellis1972
Copy link
Contributor

I tried to see if I could repo but the app does not build using
dotnet build XamlBrewerUnoApp.Mobile.csproj -bl

error UXAML0001: The type initializer for 'Uno.UI.SourceGenerators.XamlGenerator.XamlCodeGeneration' threw an exception.
 error CS0103: The name 'InitializeComponent' does not exist in the current context
error CS1061: 'PythagorasTreePage' does not contain a definition for 'InitializeComponent' and no accessible extension method 'InitializeComponent' accepting a first argument of type 'PythagorasTreePage' could be found (are you missing a using directive or an assembly reference?)
 error CS0103: The name 'Root' does not exist in the current context 

@Youssef1313
Copy link
Member Author

Youssef1313 commented Oct 13, 2023

It's strange. It's building perfectly fine in CI. What exception did XamlCodeGeneration throw?

One thing I noticed is that this task might be doing extra work because we are building in Release where AddKeepAlives is true. So I was suspecting this to be what is taking lots of time. I blindly opened a performance optimization but it might still not be where the task is spending most of its time #8422.

@Youssef1313 Youssef1313 changed the title LinkAssembliesNoShrink is expensive and is run LinkAssembliesNoShrink is expensive Oct 13, 2023
@dellis1972
Copy link
Contributor

LinkAssembliesNoShrink should not run in Release, that is a Debug Task.
Might be worth checking the properties for AndroidLinkMode in your build log to see why its running that task in Release when it should be running the normal .net linker.

@Youssef1313
Copy link
Member Author

Youssef1313 commented Oct 13, 2023

Ah, AndroidLinkMode is None. That is because we explicitly pass PublishTrimmed to false. I think we did that to actually make the build faster

@Youssef1313
Copy link
Member Author

Note: Setting AndroidAddKeepAlives to false takes it down from 9 minutes to 3 seconds.

@jpobst jpobst added the bug Component does not function as intended. label Nov 14, 2023
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Dec 7, 2023
Context: dotnet#8421

Reviewing the build log from:

    dotnet new maui
    dotnet build -f net8.0-android -bl

I noticed:

    LinkAssembliesNoShrink 3.410s
    ...
    Failed to read 'C:\Program Files\dotnet\packs\Microsoft.Android.Runtime.34.android-arm64\34.0.52\runtimes\android-arm64\lib\net8.0\Mono.Android.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'C:\Program Files\dotnet\packs\Microsoft.Android.Runtime.34.android-arm64\34.0.52\runtimes\android-arm64\lib\net8.0\Java.Interop.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\microsoft.maui.controls.compatibility\8.0.3\lib\net8.0-android34.0\Microsoft.Maui.Controls.Compatibility.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\microsoft.maui.controls.core\8.0.3\lib\net8.0-android34.0\Microsoft.Maui.Controls.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\microsoft.maui.core\8.0.3\lib\net8.0-android34.0\Microsoft.Maui.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.appcompat\1.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.AppCompat.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.fragment\1.6.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Fragment.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.drawerlayout\1.2.0.3\lib\net6.0-android31.0\Xamarin.AndroidX.DrawerLayout.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.activity\1.7.2.1\lib\net6.0-android31.0\Xamarin.AndroidX.Activity.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.core\1.10.1.2\lib\net6.0-android31.0\Xamarin.AndroidX.Core.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.recyclerview\1.3.0.3\lib\net6.0-android31.0\Xamarin.AndroidX.RecyclerView.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.viewpager\1.0.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.ViewPager.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.swiperefreshlayout\1.1.0.14\lib\net6.0-android31.0\Xamarin.AndroidX.SwipeRefreshLayout.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.cardview\1.0.0.21\lib\net6.0-android31.0\Xamarin.AndroidX.CardView.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.google.android.material\1.9.0.2\lib\net6.0-android31.0\Xamarin.Google.Android.Material.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.viewpager2\1.0.0.21\lib\net6.0-android31.0\Xamarin.AndroidX.ViewPager2.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.coordinatorlayout\1.2.0.7\lib\net6.0-android31.0\Xamarin.AndroidX.CoordinatorLayout.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\microsoft.maui.graphics\8.0.3\lib\net8.0-android34.0\Microsoft.Maui.Graphics.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.navigation.fragment\2.6.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Navigation.Fragment.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\microsoft.maui.essentials\8.0.3\lib\net8.0-android34.0\Microsoft.Maui.Essentials.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.collection\1.2.0.9\lib\net6.0-android31.0\Xamarin.AndroidX.Collection.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.vectordrawable.animated\1.1.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.VectorDrawable.Animated.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.common\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.Common.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.viewmodel\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.ViewModel.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.savedstate\1.2.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.SavedState.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.activity.ktx\1.7.2.1\lib\net6.0-android31.0\Xamarin.AndroidX.Activity.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.annotation.experimental\1.3.1.1\lib\net6.0-android31.0\Xamarin.AndroidX.Annotation.Experimental.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.annotation.jvm\1.6.0.2\lib\net6.0-android31.0\Xamarin.AndroidX.Annotation.Jvm.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.appcompat.appcompatresources\1.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.AppCompat.AppCompatResources.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.arch.core.common\2.2.0.3\lib\net6.0-android31.0\Xamarin.AndroidX.Arch.Core.Common.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.arch.core.runtime\2.2.0.3\lib\net6.0-android31.0\Xamarin.AndroidX.Arch.Core.Runtime.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.browser\1.5.0.3\lib\net6.0-android31.0\Xamarin.AndroidX.Browser.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.collection.ktx\1.2.0.9\lib\net6.0-android31.0\Xamarin.AndroidX.Collection.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.concurrent.futures\1.1.0.14\lib\net6.0-android31.0\Xamarin.AndroidX.Concurrent.Futures.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.constraintlayout\2.1.4.6\lib\net6.0-android31.0\Xamarin.AndroidX.ConstraintLayout.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.constraintlayout.core\1.0.4.6\lib\net6.0-android31.0\Xamarin.AndroidX.ConstraintLayout.Core.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.versionedparcelable\1.1.1.19\lib\net6.0-android31.0\Xamarin.AndroidX.VersionedParcelable.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.core.core.ktx\1.10.1.2\lib\net6.0-android31.0\Xamarin.AndroidX.Core.Core.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.cursoradapter\1.0.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.CursorAdapter.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.customview\1.1.0.18\lib\net6.0-android31.0\Xamarin.AndroidX.CustomView.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.customview.poolingcontainer\1.0.0.5\lib\net6.0-android31.0\Xamarin.AndroidX.CustomView.PoolingContainer.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.documentfile\1.0.1.19\lib\net6.0-android31.0\Xamarin.AndroidX.DocumentFile.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.dynamicanimation\1.0.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.DynamicAnimation.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.emoji2\1.3.0.3\lib\net6.0-android31.0\Xamarin.AndroidX.Emoji2.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.startup.startupruntime\1.1.1.7\lib\net6.0-android31.0\Xamarin.AndroidX.Startup.StartupRuntime.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.emoji2.viewshelper\1.3.0.3\lib\net6.0-android31.0\Xamarin.AndroidX.Emoji2.ViewsHelper.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.exifinterface\1.3.6.2\lib\net6.0-android31.0\Xamarin.AndroidX.ExifInterface.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.fragment.ktx\1.6.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Fragment.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.interpolator\1.0.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.Interpolator.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.legacy.support.core.utils\1.0.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.Legacy.Support.Core.Utils.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.livedata\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.LiveData.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.livedata.core\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.LiveData.Core.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.livedata.core.ktx\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.LiveData.Core.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.process\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.Process.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.runtime\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.Runtime.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.runtime.ktx\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.Runtime.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.viewmodel.ktx\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.ViewModel.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.viewmodelsavedstate\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.ViewModelSavedState.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.loader\1.1.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.Loader.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.localbroadcastmanager\1.1.0.7\lib\net6.0-android31.0\Xamarin.AndroidX.LocalBroadcastManager.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.navigation.common\2.6.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Navigation.Common.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.navigation.runtime\2.6.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Navigation.Runtime.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.navigation.ui\2.6.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Navigation.UI.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.print\1.0.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.Print.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.profileinstaller.profileinstaller\1.3.1.2\lib\net6.0-android31.0\Xamarin.AndroidX.ProfileInstaller.ProfileInstaller.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.resourceinspection.annotation\1.0.1.7\lib\net6.0-android31.0\Xamarin.AndroidX.ResourceInspection.Annotation.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.savedstate.savedstate.ktx\1.2.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.SavedState.SavedState.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.security.securitycrypto\1.1.0.1-alpha06\lib\net6.0-android31.0\Xamarin.AndroidX.Security.SecurityCrypto.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.slidingpanelayout\1.2.0.7\lib\net6.0-android31.0\Xamarin.AndroidX.SlidingPaneLayout.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.tracing.tracing\1.1.0.6\lib\net6.0-android31.0\Xamarin.AndroidX.Tracing.Tracing.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.transition\1.4.1.12\lib\net6.0-android31.0\Xamarin.AndroidX.Transition.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.vectordrawable\1.1.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.VectorDrawable.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.window\1.1.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Window.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.window.extensions.core.core\1.0.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Window.Extensions.Core.Core.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.

In general, it doesn't feel like we need `Mono.Cecil` to load symbols at
all for this task. That feels like it would be useful for `Release` mode
that is doing *real* trimming, but not in debug mode.

I disabled symbol loading in this task, but left a private
`$(_AndroidLinkAssembliesReadSymbols)` as an escape hatch if this is
ever needed.

This should avoid 74 exceptions that were try-catch'd in the build log.
jonathanpeppers added a commit that referenced this issue Jan 9, 2024
…ls (#8571)

Context: #8421

Reviewing the build log from:

    dotnet new maui
    dotnet build -f net8.0-android -bl

I noticed:

    LinkAssembliesNoShrink 3.410s
    ...
    Failed to read 'C:\Program Files\dotnet\packs\Microsoft.Android.Runtime.34.android-arm64\34.0.52\runtimes\android-arm64\lib\net8.0\Mono.Android.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'C:\Program Files\dotnet\packs\Microsoft.Android.Runtime.34.android-arm64\34.0.52\runtimes\android-arm64\lib\net8.0\Java.Interop.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\microsoft.maui.controls.compatibility\8.0.3\lib\net8.0-android34.0\Microsoft.Maui.Controls.Compatibility.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\microsoft.maui.controls.core\8.0.3\lib\net8.0-android34.0\Microsoft.Maui.Controls.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\microsoft.maui.core\8.0.3\lib\net8.0-android34.0\Microsoft.Maui.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.appcompat\1.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.AppCompat.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.fragment\1.6.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Fragment.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.drawerlayout\1.2.0.3\lib\net6.0-android31.0\Xamarin.AndroidX.DrawerLayout.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.activity\1.7.2.1\lib\net6.0-android31.0\Xamarin.AndroidX.Activity.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.core\1.10.1.2\lib\net6.0-android31.0\Xamarin.AndroidX.Core.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.recyclerview\1.3.0.3\lib\net6.0-android31.0\Xamarin.AndroidX.RecyclerView.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.viewpager\1.0.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.ViewPager.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.swiperefreshlayout\1.1.0.14\lib\net6.0-android31.0\Xamarin.AndroidX.SwipeRefreshLayout.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.cardview\1.0.0.21\lib\net6.0-android31.0\Xamarin.AndroidX.CardView.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.google.android.material\1.9.0.2\lib\net6.0-android31.0\Xamarin.Google.Android.Material.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.viewpager2\1.0.0.21\lib\net6.0-android31.0\Xamarin.AndroidX.ViewPager2.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.coordinatorlayout\1.2.0.7\lib\net6.0-android31.0\Xamarin.AndroidX.CoordinatorLayout.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\microsoft.maui.graphics\8.0.3\lib\net8.0-android34.0\Microsoft.Maui.Graphics.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.navigation.fragment\2.6.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Navigation.Fragment.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\microsoft.maui.essentials\8.0.3\lib\net8.0-android34.0\Microsoft.Maui.Essentials.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.collection\1.2.0.9\lib\net6.0-android31.0\Xamarin.AndroidX.Collection.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.vectordrawable.animated\1.1.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.VectorDrawable.Animated.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.common\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.Common.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.viewmodel\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.ViewModel.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.savedstate\1.2.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.SavedState.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.activity.ktx\1.7.2.1\lib\net6.0-android31.0\Xamarin.AndroidX.Activity.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.annotation.experimental\1.3.1.1\lib\net6.0-android31.0\Xamarin.AndroidX.Annotation.Experimental.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.annotation.jvm\1.6.0.2\lib\net6.0-android31.0\Xamarin.AndroidX.Annotation.Jvm.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.appcompat.appcompatresources\1.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.AppCompat.AppCompatResources.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.arch.core.common\2.2.0.3\lib\net6.0-android31.0\Xamarin.AndroidX.Arch.Core.Common.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.arch.core.runtime\2.2.0.3\lib\net6.0-android31.0\Xamarin.AndroidX.Arch.Core.Runtime.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.browser\1.5.0.3\lib\net6.0-android31.0\Xamarin.AndroidX.Browser.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.collection.ktx\1.2.0.9\lib\net6.0-android31.0\Xamarin.AndroidX.Collection.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.concurrent.futures\1.1.0.14\lib\net6.0-android31.0\Xamarin.AndroidX.Concurrent.Futures.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.constraintlayout\2.1.4.6\lib\net6.0-android31.0\Xamarin.AndroidX.ConstraintLayout.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.constraintlayout.core\1.0.4.6\lib\net6.0-android31.0\Xamarin.AndroidX.ConstraintLayout.Core.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.versionedparcelable\1.1.1.19\lib\net6.0-android31.0\Xamarin.AndroidX.VersionedParcelable.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.core.core.ktx\1.10.1.2\lib\net6.0-android31.0\Xamarin.AndroidX.Core.Core.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.cursoradapter\1.0.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.CursorAdapter.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.customview\1.1.0.18\lib\net6.0-android31.0\Xamarin.AndroidX.CustomView.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.customview.poolingcontainer\1.0.0.5\lib\net6.0-android31.0\Xamarin.AndroidX.CustomView.PoolingContainer.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.documentfile\1.0.1.19\lib\net6.0-android31.0\Xamarin.AndroidX.DocumentFile.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.dynamicanimation\1.0.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.DynamicAnimation.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.emoji2\1.3.0.3\lib\net6.0-android31.0\Xamarin.AndroidX.Emoji2.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.startup.startupruntime\1.1.1.7\lib\net6.0-android31.0\Xamarin.AndroidX.Startup.StartupRuntime.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.emoji2.viewshelper\1.3.0.3\lib\net6.0-android31.0\Xamarin.AndroidX.Emoji2.ViewsHelper.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.exifinterface\1.3.6.2\lib\net6.0-android31.0\Xamarin.AndroidX.ExifInterface.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.fragment.ktx\1.6.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Fragment.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.interpolator\1.0.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.Interpolator.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.legacy.support.core.utils\1.0.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.Legacy.Support.Core.Utils.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.livedata\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.LiveData.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.livedata.core\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.LiveData.Core.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.livedata.core.ktx\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.LiveData.Core.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.process\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.Process.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.runtime\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.Runtime.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.runtime.ktx\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.Runtime.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.viewmodel.ktx\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.ViewModel.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.lifecycle.viewmodelsavedstate\2.6.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.Lifecycle.ViewModelSavedState.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.loader\1.1.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.Loader.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.localbroadcastmanager\1.1.0.7\lib\net6.0-android31.0\Xamarin.AndroidX.LocalBroadcastManager.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.navigation.common\2.6.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Navigation.Common.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.navigation.runtime\2.6.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Navigation.Runtime.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.navigation.ui\2.6.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Navigation.UI.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.print\1.0.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.Print.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.profileinstaller.profileinstaller\1.3.1.2\lib\net6.0-android31.0\Xamarin.AndroidX.ProfileInstaller.ProfileInstaller.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.resourceinspection.annotation\1.0.1.7\lib\net6.0-android31.0\Xamarin.AndroidX.ResourceInspection.Annotation.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.savedstate.savedstate.ktx\1.2.1.3\lib\net6.0-android31.0\Xamarin.AndroidX.SavedState.SavedState.Ktx.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.security.securitycrypto\1.1.0.1-alpha06\lib\net6.0-android31.0\Xamarin.AndroidX.Security.SecurityCrypto.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.slidingpanelayout\1.2.0.7\lib\net6.0-android31.0\Xamarin.AndroidX.SlidingPaneLayout.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.tracing.tracing\1.1.0.6\lib\net6.0-android31.0\Xamarin.AndroidX.Tracing.Tracing.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.transition\1.4.1.12\lib\net6.0-android31.0\Xamarin.AndroidX.Transition.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.vectordrawable\1.1.0.19\lib\net6.0-android31.0\Xamarin.AndroidX.VectorDrawable.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.window\1.1.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Window.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.
    Failed to read 'D:\.nuget\packages\xamarin.androidx.window.extensions.core.core\1.0.0.1\lib\net6.0-android31.0\Xamarin.AndroidX.Window.Extensions.Core.Core.dll' with debugging symbols. Retrying to load it without it. Error details are logged below.

In general, it doesn't feel like we need `Mono.Cecil` to load symbols at
all for this task. That feels like it would be useful for `Release` mode
that is doing *real* trimming, but not in debug mode. Generally, we don't
think anyone will be debugging the assemblies changed in this
`<LinkAssembliesNoShrink/>` task. They would likely be old, precompiled
assemblies from NuGet if they need to be fixed up.

Some other issues were discovered here, addressing in:

dotnet/java-interop#1176

I disabled symbol loading in this task, but left a private
`$(_AndroidLinkAssembliesReadSymbols)` as an escape hatch if this is
ever needed.

This should avoid 74 exceptions that were try-catch'd in the build log.
@jonathanpeppers
Copy link
Member

Note: Setting AndroidAddKeepAlives to false takes it down from 9 minutes to 3 seconds.

So, are we testing Debug or Release builds? We are generally more interested in improving build times for Debug builds.

The <LinkAssembliesNoShrink/> task normally runs when the linker/trimmer is disabled (Debug mode).

However, $(AndroidKeepAlives) is only true in a Release build by default:

https://github.com/xamarin/xamarin-android/blob/2f192386e8072f8e0ecaf0de2fe48654f3ade423/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets#L944

$(AndroidIncludeDebugSymbols) is based on DebugSymbols=true or DebugType being set.

I was going to look into skipping AddKeepAlives() for any assembly that is newer than MonoAndroid12.0. But I don't see this code path even hit in a dotnet new maui project build.

@Youssef1313 do you have a .binlog of a build where you were seeing this? Was it, perhaps, Release mode?

@jonathanpeppers
Copy link
Member

@Youssef1313 your picture above is Release mode:

image

Do you have trimming disabled in this app?

@jonpryor
Copy link
Member

@jonathanpeppers asked:

Do you have trimming disabled in this app?

Yes, they do:

Ah, AndroidLinkMode is None. That is because we explicitly pass PublishTrimmed to false. I think we did that to actually make the build faster

@Youssef1313
Copy link
Member Author

@jonpryor Yes, it's the release build in CI.

jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jan 18, 2024
Context: dotnet#8421

Working a bit on build performance, I tested:

* `dotnet new maui`

* `dotnet build -bl`

The `.binlog` shows:

    LinkAssembliesNoShrink 3.797s

Attaching `dotnet-trace` as mentioned on:

https://github.com/xamarin/xamarin-android/blob/2f192386e8072f8e0ecaf0de2fe48654f3ade423/Documentation/guides/tracing.md#how-to-dotnet-trace-our-build

I see time broken down such as:

    FixAbstractMethods: 37%
    AssemblyDefinition.Write: 27%
    ProcessAssemblyDesigner: 20%
    CopyIfChanged: 13%
    DirectoryAssemblyResolver.GetAssembly: 4.4%

This made me focus in on `FixAbstractMethodsStep` and make the following
changes:

* All calls for `TypeReference.Resolve()` and `MethodReference.Resolve()`
  should go through the `TypeDefinitionCache` to avoid repeated lookups.

* `IsInOverrides()` can compare the `MethodReference.Name` before
  calling `Resolve()`. It could resolve many unnecessary methods otherwise.

After these changes, I instead see from `dotnet-trace`:

```
--1.45s (3.7%)    xamarin.android.build.tasks!MonoDroid.Tuner.FixAbstractMethodsStep.FixAbstractMethods()
++949.70ms (2.5%) xamarin.android.build.tasks!MonoDroid.Tuner.FixAbstractMethodsStep.FixAbstractMethods()
```

Time is now broken down differently, such as:

    AssemblyDefinition.Write: 31%
    FixAbstractMethods: 28%
    ProcessAssemblyDesigner: 23%
    CopyIfChanged: 12%
    DirectoryAssemblyResolver.GetAssembly: 4.8%

In an overall `.binlog` (without `dotnet-trace` attached):

```
--LinkAssembliesNoShrink 3.797s
++LinkAssembliesNoShrink 3.105s
```

This saved ~700ms on initial build of a new MAUI project.
jonpryor pushed a commit that referenced this issue Feb 7, 2024
…8650)

Context: #8421

Working a bit on build performance, I tested:

  * `dotnet new maui`

  * `dotnet build -bl`

The `.binlog` shows:

	LinkAssembliesNoShrink 3.797s

Attaching `dotnet-trace` as mentioned on:

https://github.com/xamarin/xamarin-android/blob/2f192386e8072f8e0ecaf0de2fe48654f3ade423/Documentation/guides/tracing.md#how-to-dotnet-trace-our-build

I see time broken down such as:

	FixAbstractMethods: 37%
	AssemblyDefinition.Write: 27%
	ProcessAssemblyDesigner: 20%
	CopyIfChanged: 13%
	DirectoryAssemblyResolver.GetAssembly: 4.4%

This made me focus in on `FixAbstractMethodsStep` and make the
following changes:

  * All calls for `TypeReference.Resolve()` and
    `MethodReference.Resolve()` should go through the
    `TypeDefinitionCache` to avoid repeated lookups.

  * `IsInOverrides()` can compare the `MethodReference.Name` before
    calling `Resolve()`.  It could resolve many unnecessary methods
    otherwise.

After these changes, I instead see from `dotnet-trace`:

	--1.45s (3.7%)    xamarin.android.build.tasks!MonoDroid.Tuner.FixAbstractMethodsStep.FixAbstractMethods()
	++949.70ms (2.5%) xamarin.android.build.tasks!MonoDroid.Tuner.FixAbstractMethodsStep.FixAbstractMethods()

Time is now broken down differently, such as:

	AssemblyDefinition.Write: 31%
	FixAbstractMethods: 28%
	ProcessAssemblyDesigner: 23%
	CopyIfChanged: 12%
	DirectoryAssemblyResolver.GetAssembly: 4.8%

In an overall `.binlog` (without `dotnet-trace` attached):

	--LinkAssembliesNoShrink 3.797s
	++LinkAssembliesNoShrink 3.105s

This saved ~700ms on initial build of a new MAUI project.
@jonpryor
Copy link
Member

We should look into further optimizing AddKeepAlivesStep.cs/etc. to only process assemblies built against Xamarin.Android 11.1 or older, as those versions lack #5278.

@jonpryor jonpryor modified the milestones: .NET 9, .NET 10 Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App+Library Build Issues when building Library projects or Application projects. bug Component does not function as intended.
Projects
None yet
Development

No branches or pull requests

5 participants