Remove some low-hanging fruit allocation#821
Merged
KirillOsenkov merged 1 commit intoKirillOsenkov:mainfrom Sep 17, 2024
Merged
Remove some low-hanging fruit allocation#821KirillOsenkov merged 1 commit intoKirillOsenkov:mainfrom
KirillOsenkov merged 1 commit intoKirillOsenkov:mainfrom
Conversation
- Avoid closures when calling TreeNode.Find{Last}Child. Added an overload that takes state, and made all call sites use `static` to help flag places state was being closed over.
- Avoid closures in BuildEventArgs.Read. The error paths were closing over state used by the success path, resulting in allocation even on success.
- Changed some methods that were returning interfaces to return the strongly-typed collection instead. Consumers that were iterating through them can now automatically avoid going through an enumerator.
- Avoid params allocations for most call sites to FormatResourceStringIgnoreCodeAndKeyword by adding dedicated overloads for 1/2/3 args.
- Avoid an int boxing allocation (on core) when concatening a string with an int.
- Updated TextUtilities to use more modern APIs, e.g. MemoryExtensions.IndexOfAny, IndexOf, ReplaceLineEndings, etc. Some uses were (accidentally?) using Enumerable.Contains.
KirillOsenkov
approved these changes
Sep 17, 2024
Owner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


@KirillOsenkov asked me to look at why the .NET 8 build was slower than the .NET Framework build (answer: #819), and why so much time was being taken up in ReadByte (answer: #820, dotutils/streamutils#2). But while looking into it, I did an allocation profile and noticed some low-hanging fruit easily avoided, so this addresses those.
staticto help flag places state was being closed over.