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

Modify ISyntaxFacts methods to allocate less #74596

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

ToddGrun
Copy link
Contributor

CSharpSyntaxFacts.GetMethodLevelMembers shows up as 3.4% of allocations in the scrolling speedometer test during the typing phase of the test. This method (and it's partner GetTopLevelAndMethodLevelMembers) can be easily made to take in and populate an arraybuilder instead of allocating a list on each invocation.

*** relevant allocation data from scrolling speedometer profile during typing part of the test ***
image

CSharpSyntaxFacts.GetMethodLevelMembers shows up as 3.4% of allocations in the scrolling speedometer test during the typing phase of the test. This method (and it's partner GetTopLevelAndMethodLevelMembers) can be easily made to take in and populate an arraybuilder instead of allocating a list on each invocation.
@ToddGrun ToddGrun requested a review from a team as a code owner July 30, 2024 02:07
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 30, 2024
@ToddGrun ToddGrun merged commit 44b1859 into dotnet:main Jul 30, 2024
25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 30, 2024
ToddGrun added a commit to ToddGrun/roslyn that referenced this pull request Aug 16, 2024
A recent change(dotnet#74596) modified this code to take in an ArrayBuilder to allow callers to easily use pooled arrays. However, the size of the data populated into those arrays commonly exceeds the ArrayBuilder reuse threshold, those reducing the allocation benefit realized in those codepaths.

This PR changes the callers to instead use a pooled list, thus avoiding the threshold issue. Current scrolling speedometer results for the typing scenario still show this as allocating around 35 MB (which was about 3.5% at the time of the earlier PR). My hope is that this PR will get rid of nearly all those allocations this time.
ToddGrun added a commit that referenced this pull request Aug 21, 2024
* Reduce usage in CSharpSyntaxFacts.AppendMembers (again)

A recent change(#74596) modified this code to take in an ArrayBuilder to allow callers to easily use pooled arrays. However, the size of the data populated into those arrays commonly exceeds the ArrayBuilder reuse threshold, those reducing the allocation benefit realized in those codepaths.

This PR changes the callers to instead receive back a PooledObject<List<SyntaxNode>>, thus avoiding the threshold issue, and letting the callers release the List back to the pool at their own discretion. Current scrolling speedometer results for the typing scenario still show this as allocating around 35 MB (which was about 3.5% at the time of the earlier PR). Speedometer runs including this PR have none of those allocations.
@dibarbet dibarbet modified the milestones: Next, 17.12 P2 Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants