Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 16, 2025

The pattern <ItemType Remove="@(ItemType)" /> already had fast-path optimization during project evaluation but was doing expensive file system operations during target execution.

Changes

  • ItemGroupIntrinsicTask.ExecuteRemove: Added early detection for self-reference pattern before calling FindItemsMatchingSpecification

    • When detected, directly converts items to list instead of expanding references, glob matching, and building HashSets
    • Handles whitespace and case-insensitive item type names
  • Tests: Added coverage for whitespace, case sensitivity, many items, and items with metadata

Example

<Target Name="Clean">
  <ItemGroup>
    <!-- Previously: expensive expansion + file system operations -->
    <!-- Now: direct list conversion -->
    <TempFiles Remove="@(TempFiles)" />
  </ItemGroup>
</Target>

The optimization now applies consistently in both evaluation phase (LazyItemEvaluator) and execution phase (ItemGroupIntrinsicTask).

Original prompt

This section details on the original issue you should resolve

<issue_title>Fast clear all items primitive</issue_title>
<issue_description>We should detect the pattern for clearing all items and make it super cheap and fast:

    <!-- Remove items which we will never again use - they just sit around taking up memory otherwise -->
    <ItemGroup>
      <_AllChildProjectItemsWithTargetPath Remove="@(_AllChildProjectItemsWithTargetPath)"/>
    </ItemGroup>
    <ItemGroup>
      <Foo Remove="@(Foo)" />
    </ItemGroup>
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@dotnet-policy-service
Copy link
Contributor

Hello @@copilot, I noticed that you’re changing an .swr file or any file under src/Package/MSBuild.VSSetup.. Please make sure to validate this change by an experimental VS insertion. This is accomplished by pushing to an exp/* branch, which requires write permissions to this repo.

Copilot AI changed the title [WIP] Add fast clear all items primitive Optimize self-reference item removal in target execution Nov 16, 2025
Copilot AI requested a review from JanProvaznik November 16, 2025 22:13
Copilot finished work on behalf of JanProvaznik November 16, 2025 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fast clear all items primitive

2 participants