Skip to content

Item batching can be very slow, especially on Linux #2516

@dsplaisted

Description

@dsplaisted

Changing an item include to include some additional metadata resulted in extreme slowdowns for me, especially on Linux:

OS Without metadata With metadata
Windows 10 ms 8234 ms
Linux 68 ms 143022 ms

The change that caused this was changing from:

<_RuntimeTargetPublishItems Include="@(FileDefinitions)" Exclude="@(__RuntimeTargetPublishItems)" />

To:

<_RuntimeTargetPublishItems Include="@(FileDefinitions)" Exclude="@(__RuntimeTargetPublishItems)" 
                            DestinationSubPath="%(FileDefinitions.Path)" />

Repro steps

  • git clone https://github.com/dsplaisted/msbuild-slow-batching
  • cd msbuild-slow-batching
  • cd TestApp
  • dotnet build /clp:PerformanceSummary
  • Observe the difference in execution time between the FastBatching and SlowBatching targets in the performance summary

EXPECTED: Execution times are comparable
ACTUAL: SlowBatching execution time is several orders of magnitude slower than FastBatching

Repro details

The repro project is an app targeting netcoreapp1.1 referencing a library which targets netstandard1.5. The app project has the following targets added to it:

  <Target Name="SetupItemsForBatching" AfterTargets="Build" DependsOnTargets="_ComputeLockFileCopyLocal">
    <ItemGroup>
      <TestItems1 Include="@(_ActiveTFMFileDependencies->WithMetadataValue('FileGroup', 'RuntimeTarget'))" />
      <TestItems2 Include="@(FileDefinitions)" Exclude="@(TestItems1)" />
    </ItemGroup>
  </Target>

  <Target Name="SlowBatching" AfterTargets="Build" DependsOnTargets="SetupItemsForBatching">
    <ItemGroup>
      <SlowBatchItems Include="@(FileDefinitions)" Exclude="@(TestItems2)"
                      DestinationSubPath="%(FileDefinitions.Path)"/>
    </ItemGroup>
  </Target>

  <Target Name="FastBatching" AfterTargets="Build" DependsOnTargets="SetupItemsForBatching">
    <ItemGroup>
      <FastBatchItems Include="@(FileDefinitions)" Exclude="@(TestItems2)" />      
    </ItemGroup>
  </Target>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions