Skip to content

No-op build spends an unreasonable amount of time in the ChooseBestTargetFrameworksTask task #105138

Open
@ViktorHofer

Description

@ViktorHofer

This is from a fully no-op build of a reference source project that doesn't have any dependencies:

C:\git\runtime4>.\.dotnet\dotnet.exe msbuild /t:Build /v:minimal /clp:performancesummary C:\git\runtime4\src\libraries\System.Runtime\ref\System.Runtime.csproj

  System.Runtime -> C:\git\runtime4\artifacts\bin\System.Runtime\ref\Debug\net9.0\System.Runtime.dll

Project Evaluation Performance Summary:
      557 ms  C:\git\runtime4\src\libraries\System.Runtime\ref\System.Runtime.csproj   1 calls

Project Performance Summary:
      347 ms  C:\git\runtime4\src\libraries\System.Runtime\ref\System.Runtime.csproj   1 calls
                347 ms  Build                                      1 calls

Target Performance Summary:
        0 ms  ResGen                                     1 calls
        0 ms  PrepareResourceNames                       1 calls
        0 ms  PrepareResources                           1 calls
        0 ms  AfterResGen                                1 calls
        0 ms  BeforeResGen                               1 calls
        0 ms  ResolvePackageDependenciesForBuild         1 calls
        0 ms  GetReferenceAssemblyPaths                  1 calls
        0 ms  CreateCustomManifestResourceNames          1 calls
        0 ms  ValidateCommandLineProperties              1 calls
        0 ms  GenerateSourceLinkFile                     1 calls
        0 ms  InitializeSourceControlInformation         1 calls
        0 ms  CreateSatelliteAssemblies                  1 calls
        0 ms  BeforeCompile                              1 calls
        0 ms  ConfigureGenerators                        1 calls
        0 ms  AfterBuild                                 1 calls
        0 ms  _CopySourceItemsToOutputDirectory          1 calls
        0 ms  GetFrameworkPaths                          1 calls
        0 ms  CoreBuild                                  1 calls
        0 ms  SetWin32ManifestProperties                 1 calls
        0 ms  BeforeBuild                                1 calls
        0 ms  GenerateMSBuildEditorConfigFile            1 calls
        0 ms  Deploy                                     1 calls
        0 ms  AfterCompile                               1 calls
        0 ms  BeforeResolveReferences                    1 calls
        0 ms  Compile                                    1 calls
        0 ms  BuildOnlySettings                          1 calls
        0 ms  ResolveLockFileAnalyzers                   1 calls
        0 ms  EnableIntermediateOutputPathMismatchWarning   1 calls
        0 ms  _CustomizeResourceNames                    1 calls
        0 ms  PrepareProjectReferences                   1 calls
        0 ms  PrepareForRun                              1 calls
        0 ms  IncludeTransitiveProjectReferences         1 calls
        0 ms  GenerateAssemblyInfo                       1 calls
        0 ms  BinPlace                                   1 calls
        0 ms  GetTargetPath                              1 calls
        0 ms  _AddOutputPathToGlobalPropertiesToRemove   1 calls
        0 ms  Build                                      1 calls
        0 ms  AfterResolveReferences                     1 calls
        0 ms  _SetTargetFrameworkMonikerAttribute        1 calls
        0 ms  ResolveReferences                          1 calls
        0 ms  VerifyBuildFlags                           1 calls
        0 ms  _PopulateCommonStateForGetCopyToOutputDirectoryItems   1 calls
        0 ms  _DefaultMicrosoftNETPlatformLibrary        1 calls
        0 ms  _CheckForUnsupportedHostingUsage           1 calls
        0 ms  _ComputeNETCoreBuildOutputFiles            1 calls
        0 ms  CopyAdditionalFiles                        1 calls
        0 ms  _ComputeUserRuntimeAssemblies              1 calls
        0 ms  IgnoreJavaScriptOutputAssembly             1 calls
        0 ms  _BeforeVBCSCoreCompile                     1 calls
        0 ms  _GenerateResxSource                        1 calls
        0 ms  _CheckAndUnsetUnsupportedPrefer32Bit       1 calls
        0 ms  _CheckForObsoleteDotNetCliToolReferences   1 calls
        0 ms  ShimReferencePathsWhenCommonTargetsDoesNotUnderstandReferenceAssemblies   1 calls
        0 ms  _CheckForUnsupportedCppNETCoreVersion      1 calls
        0 ms  UseTargetingPackForAssemblySearchPaths     1 calls
        0 ms  FindReferenceAssembliesForReferences       1 calls
        0 ms  _CheckForUnsupportedArtifactsPath          1 calls
        0 ms  ResolveLockFileCopyLocalFiles              1 calls
        0 ms  ResolveSDKReferences                       1 calls
        0 ms  AddOSPlatformAttributes                    1 calls
        0 ms  GetAssemblyVersion                         1 calls
        0 ms  RemoveSupportedOSTargetPlatformAttributeFromProjects   1 calls
        0 ms  ExpandSDKReferences                        1 calls
        0 ms  GenerateMSBuildEditorConfigFileShouldRun   1 calls
        0 ms  AddImplicitDefineConstants                 1 calls
        0 ms  _SplitProjectReferencesByFileExistence     1 calls
        0 ms  _BatchGenerateResxSource                   1 calls
        0 ms  GetTargetPathWithTargetPlatformMoniker     1 calls
        0 ms  _InitializeAssemblyVersion                 1 calls
        0 ms  _ComputeReferenceAssemblies                1 calls
        0 ms  _CheckForLanguageAndFeatureCombinationSupport   1 calls
        0 ms  CoreResGen                                 1 calls
        0 ms  _ComputeSkipAnalyzers                      1 calls
        0 ms  _GenerateCompileInputs                     1 calls
        0 ms  _GetProjectJsonPath                        1 calls
        0 ms  _CheckContainersPackage                    1 calls
        0 ms  _GenerateSatelliteAssemblyInputs           1 calls
        0 ms  _CheckForCompileOutputs                    1 calls
        0 ms  ValidateReferenceAssemblyProjectReferencesAndTargetFramework   1 calls
        0 ms  _GetCopyToOutputDirectoryItemsFromThisProject   1 calls
        0 ms  AddGlobalAnalyzerConfigForPackage_MicrosoftCodeAnalysisCSharpCodeStyle   1 calls
        0 ms  ResolveProjectReferences                   1 calls
        1 ms  ResolveAssemblyReferences                  1 calls
        1 ms  _CheckForUnsupportedNETCoreVersion         1 calls
        1 ms  _BlockWinMDsOnUnsupportedTFMs              1 calls
        1 ms  GetBinPlaceItems                           1 calls
        1 ms  _GetCopyToOutputDirectoryItemsFromTransitiveProjectReferences   1 calls
        1 ms  FlagNetStandard1xDependencies              1 calls
        1 ms  ResolveKeySource                           1 calls
        1 ms  ResolveLockFileReferences                  1 calls
        1 ms  _ComputePackageReferencePublish            1 calls
        1 ms  GetAssemblyAttributes                      1 calls
        1 ms  SplitResourcesByCulture                    1 calls
        1 ms  GenerateBuildDependencyFile                1 calls
        1 ms  _TouchLastBuildWithSkipAnalyzers           1 calls
        2 ms  CoreGenerateAssemblyInfo                   1 calls
        2 ms  CoreCompile                                1 calls
        2 ms  AssignTargetPaths                          1 calls
        2 ms  CheckForImplicitPackageReferenceOverrides   1 calls
        2 ms  IncrementalClean                           1 calls
        2 ms  ValidateExecutableReferences               1 calls
        2 ms  _GenerateCompileDependencyCache            1 calls
        2 ms  _GetRestoreProjectStyle                    1 calls
        2 ms  CheckForDuplicateItems                     1 calls
        3 ms  UpdateAspNetToFrameworkReference           1 calls
        3 ms  GenerateNETCompatibleDefineConstants       1 calls
        3 ms  ApplyImplicitVersions                      1 calls
        3 ms  GenerateTargetFrameworkMonikerAttribute    1 calls
        3 ms  _HandlePackageFileConflicts                1 calls
        3 ms  CreateGeneratedAssemblyInfoInputsCacheFile   1 calls
        4 ms  _CheckForInvalidConfigurationAndPlatform   1 calls
        4 ms  _SetEmbeddedWin32ManifestProperties        1 calls
        4 ms  _ComputeToolPackInputsToProcessFrameworkReferences   1 calls
        5 ms  BinPlaceFiles                              2 calls
        6 ms  _CleanGetCurrentAndPriorFileWrites         1 calls
        6 ms  CopyFilesToOutputDirectory                 1 calls
        7 ms  ResolvePackageAssets                       1 calls
        7 ms  GenerateMSBuildEditorConfigFileCore        1 calls
        9 ms  CollectPackageReferences                   1 calls
       12 ms  GetCopyToOutputDirectoryItems              1 calls
       22 ms  _CollectTargetFrameworkForTelemetry        1 calls
       42 ms  _GetProjectReferenceTargetFrameworkProperties   1 calls
       45 ms  PrepareForBuild                            1 calls
      102 ms  GetBinPlaceTargetFramework                 1 calls

Task Performance Summary:
        0 ms  AssignCulture                              1 calls
        0 ms  CheckForUnsupportedWinMDReferences         1 calls
        0 ms  ConvertToAbsolutePath                      1 calls
        0 ms  Delete                                     1 calls
        0 ms  ResolveKeySource                           1 calls
        0 ms  FindAppConfigFile                          1 calls
        0 ms  ApplyImplicitVersions                      1 calls
        0 ms  JoinItems                                  1 calls
        1 ms  RemoveDuplicates                           2 calls
        1 ms  SetRidAgnosticValueForProjects             1 calls
        1 ms  MSBuild                                    1 calls
        1 ms  Touch                                      1 calls
        1 ms  ValidateExecutableReferences               1 calls
        1 ms  CheckForDuplicateNuGetItemsTask            1 calls
        1 ms  CheckForImplicitPackageReferenceOverrides   1 calls
        1 ms  AssignTargetPath                           6 calls
        1 ms  ReadLinesFromFile                          1 calls
        1 ms  Hash                                       2 calls
        2 ms  CheckIfPackageReferenceShouldBeFrameworkReference   2 calls
        2 ms  GetRestoreProjectStyleTask                 1 calls
        2 ms  CheckForDuplicateItems                     3 calls
        2 ms  FindUnderPath                              5 calls
        2 ms  ResolvePackageFileConflicts                1 calls
        2 ms  Message                                    5 calls
        3 ms  WriteLinesToFile                           2 calls
        3 ms  GenerateMSBuildEditorConfig                1 calls
        3 ms  GetFrameworkPath                           1 calls
        4 ms  AllowEmptyTelemetry                        1 calls
        5 ms  ResolvePackageAssets                       1 calls
        7 ms  MakeDir                                    1 calls
        8 ms  CallTarget                                 2 calls
        8 ms  Copy                                       3 calls
       99 ms  ChooseBestTargetFrameworksTask             1 calls

Code path: https://github.com/dotnet/arcade/blob/6d13437862aac429c56ab1516ac0a434ef9a2b94/src/Microsoft.DotNet.Build.Tasks.TargetFramework/src/build/BinPlace.targets#L76-L82

Binlog details:
image


A few observations:

  1. Reference source projects never target OS specific TFMs. All inbox libraries target $(NetCoreAppCurrent) already so this entire calculation is unnecessary.
  2. There might be an opportunity to skip this entire logic. Neither the GetBinPlaceTargetFramework nor the BinPlaceFiles targets define inputs & outputs so they always run. I wonder if the entry point target BinPlace could already define appropriate inputs & outputs.
  3. The time it takes to evaluate the project is extremely high. I will file a separate issue for that: Poor project evaluation performance for project at least under src/libraries #105139

@dotnet/area-infrastructure-libraries

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions