Skip to content
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

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

Merged
merged 2 commits into from
May 15, 2020

Conversation

rainersigwald
Copy link
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
Copy link
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
{
// Perf optimization: If the Remove operation references itself (e.g. <I Remove="@(I)"/>)
// then all items are removed and matching is not necessary
listBuilder.RemoveAll((_) => true);
Copy link
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
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