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 again in BlockStructure collection #74627

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

ToddGrun
Copy link
Contributor

@ToddGrun ToddGrun commented Aug 1, 2024

There are basically two places where array allocations have been improved (particularly when the array exceed the default array builder pool size).

  1. AbstractBlockStructureProvider.ProvideBlockStructure now calls BlockSpanCollector.CollectBlockSpans with the context.Spans, not with a new TemporaryArray. This required a change to the Sort call to pass in the start index, and to the filtering code at the end of the method to only filter out from the range that the current provider added to context.Spans

  2. BlockStructureContext has it's own pool for the ArrayBuilder. As this array was very commonly exceeding the maximum reusable size allowed in the default array pool, we were previously no placing these arrays back in a pool.

Note that BlockStructureServiceWithProviders.CreateBlockStructure no longer uses FixedSizeArrayBuilder, instead modifying the entries in place. There isn't really an allocation change in this method, as both old and new allocate a single array in this method.

After the GetMultiLineRegions change earlier today, these allocations are only about 0.8% in the scrolling speedometer profile I'm looking at. Of that, I'd expect this to only remove about half of that, so only somewhat impactful.

*** relevant allocations from scrolling speedometer profile ***
image

There are basically two places where array allocations have been improved (particularly when the array exceed the default array builder pool size).

1) AbstractBlockStructureProvider.ProvideBlockStructure now calls BlockSpanCollector.CollectBlockSpans with the context.Spans, not with a new TemporaryArray. This required a change to the Sort call to pass in the start index, and to the filtering code at the end of the method to only filter out from the range that the current provider added to context.Spans

2) BlockStructureContext has it's own pool for the ArrayBuilder<BlockSpan>. As this array was very commonly exceeding the maximum reusable size allowed in the default array pool, we were previously no placing these arrays back in a pool.

Note that BlockStructureServiceWithProviders.CreateBlockStructure no longer uses FixedSizeArrayBuilder, instead modifying the entries in place. There isn't really an allocation change in this method, as both old and new allocate a single array in this method.
@ToddGrun ToddGrun requested a review from a team as a code owner August 1, 2024 00:38
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 1, 2024
@ToddGrun
Copy link
Contributor Author

ToddGrun commented Aug 6, 2024

@CyrusNajmabadi -- ptal

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