-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Make Remove-all-items O(1) #5350
Conversation
There was a problem hiding this 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
I want to use this in another subclass.
6db3fe3
to
4459ab7
Compare
{ | ||
// 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
listBuilder.RemoveAll((_) => true); | |
listBuilder.Clear(); |
There was a problem hiding this comment.
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.
4459ab7
to
811b648
Compare
In the special case where a remove operation removes all items like
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/.