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

Reduce allocations in the C# lexer ctor #76544

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ToddGrun
Copy link
Contributor

@ToddGrun ToddGrun commented Dec 20, 2024

The lexer ctor shows as about 0.6% of all allocations over the lifetime of the RoslynCodeAnalysisProcess in the csharp editing speedometer tests.

There was already the concept of the LexerCache which had some pooling usage in it. This PR moves a couple other members to it to allow for their pooling.

Speedometer results look quite promising:

Allocations under Lexer.ctor in IncPaths reduced from 60 MB to 1.5 MB
Allocations under Lexer in IncPaths reduced from 1.57 GB to 1.36 GB

The lexer ctor shows as about 0.5% of all allocations over the lifetime of the RoslynCodeAnalysisProcess in the csharp editing speedometer tests.

There was already the concept of the LexerCache which had some pooling usage in it. This PR moves a couple other members to it to allow for their pooling.

This PR is going to be marked as a draft PR until I can get some data from a test insertion indicating whether these changes improve allocations in the speedometer tests.
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 20, 2024
@ToddGrun
Copy link
Contributor Author

ToddGrun commented Dec 20, 2024

@ToddGrun
Copy link
Contributor Author

Speedometer results look promising, going to promote out of draft mode.

Allocations under Lexer.*ctor in IncPaths:
60 MB -> 1.5 MB
Allocations under Lexer in IncPaths:
1,57 GB -> 1.36 GB

@ToddGrun ToddGrun changed the title WIP: Attempt to reduce allocations in the C# lexer ctor Reduce allocations in the C# lexer ctor Dec 21, 2024
@ToddGrun ToddGrun marked this pull request as ready for review December 21, 2024 13:59
@ToddGrun ToddGrun requested a review from a team as a code owner December 21, 2024 13:59
@ToddGrun
Copy link
Contributor Author

@dotnet/roslyn-compiler -- ptal

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 1)

@ToddGrun
Copy link
Contributor Author

ToddGrun commented Jan 2, 2025

@AlekseyTs -- changes made based on your commit 1 pass suggestions

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 2)

@ToddGrun
Copy link
Contributor Author

ToddGrun commented Jan 2, 2025

This has changed enough since the first commit where I ran a test insertion that I will run one again (once Aleksey has signed off) just to make sure the numbers still look good.

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 3)

…ng something out in this area and forgot to revert that change)
Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 4)

@ToddGrun
Copy link
Contributor Author

ToddGrun commented Jan 3, 2025

Test insertion for speedometer results of commit 4:

https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/600635

@ToddGrun
Copy link
Contributor Author

ToddGrun commented Jan 3, 2025

Allocations under the lexer still look improved with latest test insertion.

@dotnet/roslyn-compiler for 2nd review. Thanks!

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.

2 participants