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

Change SyntaxEquivalence.AreEquivalent to use a more appropriate pooling mechanism for the stack it uses to walk trees. #74610

Conversation

ToddGrun
Copy link
Contributor

The scrolling speedometer test indicates this method's pooling mechanism isn't working great for large files. Specifically, ArrayBuilder instances aren't returned to their pool once their length exceeds 128 items. For even relatively large files, I'm seeing this exceeded in this context.

Instead, I've switched this code to just use a pooled Stack. This was accounting for about 1.1% of allocations in the typing scenario for the scrolling speedometer test.

*** relevant allocations from the typing scenario in the scrolling speedometer test ***
image

…ing mechanism for the stack it uses to walk trees.

The scrolling speedometer test indicates this method's pooling mechanism isn't working great for large files. Specifically, ArrayBuilder instances aren't returned to their pool once their length exceeds 128 items. For even relatively large files, I'm seeing this exceeded in this context.

Instead, I've switched this code to just use a pooled Stack. This was accounting for about 1.1% of allocations in the typing scenario for the scrolling speedometer test.
@ToddGrun ToddGrun requested a review from a team as a code owner July 30, 2024 22:56
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 30, 2024
@ToddGrun
Copy link
Contributor Author

tests failing, need to investigate

@ToddGrun
Copy link
Contributor Author

Duh. There's a code path where the stack isn't null when hitting the finally, so it needs to be cleared before being placed back in the pool.


In reply to: 2259388249

@@ -117,7 +121,8 @@ private static bool AreEquivalentRecursive(GreenNode? before, GreenNode? after,
}
finally
{
stack.Free();
stack.Clear();
s_equivalenceCheckStack.Free(stack);
Copy link
Member

Choose a reason for hiding this comment

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

is there not FreeAndClear/ClearAndFree?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's defined at the workspace level

Copy link
Member

Choose a reason for hiding this comment

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

well that's silly :)

Copy link
Member

Choose a reason for hiding this comment

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

I would be fine to move that down if you wanted.

Copy link
Member

@333fred 333fred Jul 31, 2024

Choose a reason for hiding this comment

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

Though I will point out that those helpers stop returning pooled objects after they get to 512 items. That might not work well here either.

@ToddGrun
Copy link
Contributor Author

@dotnet/roslyn-compiler -- ready for review

@ToddGrun
Copy link
Contributor Author

@dotnet/roslyn-compiler for 2nd review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers 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.

5 participants