Skip to content

Make Remove-all-items O(1)#5350

Merged
rainersigwald merged 2 commits into
dotnet:masterfrom
rainersigwald:optimized-remove-all
May 15, 2020
Merged

Make Remove-all-items O(1)#5350
rainersigwald merged 2 commits into
dotnet:masterfrom
rainersigwald:optimized-remove-all

Conversation

@rainersigwald
Copy link
Copy Markdown
Member

In the special case where a remove operation removes all items like

<Compile Remove="@(Compile)" />

We currently have poor behavior because we match ("everything matches")
and then remove items one at a time. Instead, we can just empty out the
list.

Fixes #2314. Encouraged to finally do this by @maartenba's blog post https://blog.jetbrains.com/dotnet/2020/05/11/story-csproj-large-solutions-memory-usage/.

@rainersigwald rainersigwald requested a review from cdmihai May 12, 2020 16:58
Comment thread src/Build/Evaluation/LazyItemEvaluator.RemoveOperation.cs Outdated
Comment thread src/Build/Evaluation/LazyItemEvaluator.RemoveOperation.cs Outdated
Copy link
Copy Markdown
Contributor

@cdmihai cdmihai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Make sure this PR does not close #2314, since the issue has multiple bullets with more potential perf optimizations. I am actually surprised nobody measurably ran into the perf issue that would require the dictionary lookup optimization

@rainersigwald rainersigwald force-pushed the optimized-remove-all branch from 6db3fe3 to 4459ab7 Compare May 14, 2020 21:59
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
listBuilder.RemoveAll((_) => true);
listBuilder.Clear();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ I swear I used and/or looked for this before. Thanks!

In the special case where a remove operation removes all items like

```xml
<Compile Remove="@(Compile)" />
```

We currently have poor behavior because we match ("everything matches")
and then remove items one at a time. Instead, we can just empty out the
list.

Part of dotnet#2314.
@rainersigwald rainersigwald force-pushed the optimized-remove-all branch from 4459ab7 to 811b648 Compare May 15, 2020 14:12
@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label May 15, 2020
@rainersigwald rainersigwald merged commit 31a1a34 into dotnet:master May 15, 2020
@rainersigwald rainersigwald deleted the optimized-remove-all branch May 15, 2020 16:29
@ghost ghost added this to the current-release milestone May 15, 2020
Forgind added a commit that referenced this pull request Dec 3, 2020
Optimization for RemoveOperation neglected to consider condition. Fixes that and adds a test.

Fixes #5766

Introduced by #5350
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update and Remove should optimize on identity matches

5 participants