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 ProjectState's ctor #76369

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

ToddGrun
Copy link
Contributor

The AsyncLazy allocations in the ProjectState ctor are accounting for 0.6% of allocations during the typing scenario in the csharp editing speedometer test.

The construction of these objects can be deferred until they are queried (or copied). Local testing has about 80-90% of these lazy objects never being used, so this should save at around 0.5% of the allocations in this scenario.

image

The AsyncLazy allocations in the ProjectState ctor are accounting for 0.6% of allocations during the typing scenario in the csharp editing speedometer test.

The construction of these objects can be deferred until they are queried (or copied). Local testing has about 80-90% of these lazy objects never being used, so this should save at around 0.5% of the allocations in this scenario.
@ToddGrun ToddGrun requested a review from a team as a code owner December 11, 2024 05:42
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 11, 2024
{
get
{
_lazyChecksums ??= AsyncLazy.Create(static (self, cancellationToken) => self.ComputeChecksumsAsync(cancellationToken), arg: this);
Copy link
Member

Choose a reason for hiding this comment

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

i'm oogy on this. there's a race here where multipel threads could see null and assign a new value. I'm not 100% convinced that computing the checksum is guaranteed to produce the exact same result both times.

can you make this an interlocked CAS so only one wins?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I can do that. I was definitely under the impression that computing the checksum would generate the same values if it happened to get unlucky and run multiple times.

Copy link
Member

Choose a reason for hiding this comment

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

i want to believe that that would be the case... but i don't think it's proven to be true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, switched to use Interlocked.CompareExchange

…verlapping work does occur, then have both callers use the same result.
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 VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants