-
Notifications
You must be signed in to change notification settings - Fork 519
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
[Xamarin.Android.Build.Tasks] improve incremental design-time builds #6406
[Xamarin.Android.Build.Tasks] improve incremental design-time builds #6406
Conversation
Alternate solution idea: instead of updating <Touch Files="$(_AndroidManagedResourceDesignerFile)" /> This keeps the logic within the target. |
I was testing .NET MAUI projects inside Visual Studio, and noticed on solution load two sets of builds run for each `$(TargetFramework)`: 1. `CollectPackageReferences;CollectFrameworkReferences;CollectUpToDateCheckBuiltDesignTime;CollectPackageDownloads;GenerateSupportedTargetFrameworkAlias;CollectAnalyzersDesignTime;CollectUpToDateCheckInputDesignTime;CollectUpToDateCheckOutputDesignTime;CollectSuggestedWorkloads;CollectCentralPackageVersions;CompileDesignTime;CollectResolvedCompilationReferencesDesignTime` 2. `ResolveFrameworkReferencesDesignTime;ResolveProjectReferencesDesignTime2;CollectResolvedSDKReferencesDesignTime;ResolveComReferencesDesignTime;ResolveAssemblyReferencesDesignTime;ResolvePackageDependenciesDesignTime;CollectSuggestedWorkloads` 1) net6.0-maccatalyst 0.344s 1) net6.0-ios 0.353s 1) net6.0-android 1.466s 2) net6.0-maccatalyst 0.063s 2) net6.0-ios 0.059s 2) net6.0-android 1.424s Android is the worst in both cases, due to: GenerateResourceDesigner 737ms GenerateResourceDesigner 766ms I'm not sure how I got in this state, but the `_ManagedUpdateAndroidResgen` MSBuild target *never* skips for me: Building target "_ManagedUpdateAndroidResgen" completely. Input file "C:\Program Files\dotnet\sdk-manifests\6.0.100\microsoft.net.sdk.maui\WorkloadManifest.targets" is newer than output file "obj\Debug\net6.0-android\designtime\Resource.designer.cs". Reviewing the `<GenerateResourceDesigner/>` MSBuild task, there is a case it doesn't update the timestamp on the `Resource.designer.cs` output file. It is missing the pattern we have in other tasks: if (Files.CopyIfStreamChanged (o.BaseStream, file)) { Log.LogDebugMessage ($"Writing to: {file}"); } else { // NOTE: We still need to update the timestamp on this file, or the target would run again File.SetLastWriteTimeUtc (file, DateTime.UtcNow); } While I was at it, I switched from using a `new StreamWriter()` to `MemoryStreamPool`. `MemoryStreamPool` usage saw a modest improvement: Before: GenerateResourceDesigner 491ms After: GenerateResourceDesigner 480ms Overall these changes should improve all design-time builds by ~11ms, and some incremental design-time builds will properly skip: saving up to ~766ms.
b46eab4
to
faa7375
Compare
This looks good. the commit message needs updating to reflect the new changed (i.e using |
I updated the PR description, we can copy paste that when we merge. |
I was testing .NET MAUI projects inside Visual Studio, and noticed on
solution load two sets of builds run for each
$(TargetFramework)
:CollectPackageReferences;CollectFrameworkReferences;CollectUpToDateCheckBuiltDesignTime;CollectPackageDownloads;GenerateSupportedTargetFrameworkAlias;CollectAnalyzersDesignTime;CollectUpToDateCheckInputDesignTime;CollectUpToDateCheckOutputDesignTime;CollectSuggestedWorkloads;CollectCentralPackageVersions;CompileDesignTime;CollectResolvedCompilationReferencesDesignTime
ResolveFrameworkReferencesDesignTime;ResolveProjectReferencesDesignTime2;CollectResolvedSDKReferencesDesignTime;ResolveComReferencesDesignTime;ResolveAssemblyReferencesDesignTime;ResolvePackageDependenciesDesignTime;CollectSuggestedWorkloads
Android is the worst in both cases, due to:
I'm not sure how I got in this state, but the
_ManagedUpdateAndroidResgen
MSBuild target never skips for me:Reviewing the
<GenerateResourceDesigner/>
MSBuild task, there is acase it doesn't update the timestamp on the
Resource.designer.cs
output file. I added a
<Touch/>
call to solve this issue:This is a nice solution, as it is localized to the MSBuild target where the
Inputs
andOutputs
are.While I was at it, I switched from using a
new StreamWriter()
toMemoryStreamPool
.MemoryStreamPool
usage saw a modest improvement:Overall these changes should improve all design-time builds by ~11ms,
and some incremental design-time builds will properly skip: saving up
to ~766ms.