roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Reduce ImmutableDictionary allocations under SolutionCompilationState by using ImmutableSegmentedDictionary

Open ToddGrun opened this issue 1 year ago • 5 comments

The _projectIdToTrackerMap member is heavily indicted in the non-devenv allocations in the CompletionTest.Completions speedometer test (over 1 GB of allocations).

As this member is private, we have the ability to tweak this to not be an ImmutableDictionary.

This PR is an attempt to see if switching to ImmutableSegmentedDictionary is advantageous (at the suggestion of Sam). It also keeps changes from an earlier PR that allows callers to CreateCompilationTrackerMap to modify the dictionary data used to create the resultant ImmutableSegmentedDictionary.

*** Speedometer profile excerpt: before changes *** image

ToddGrun avatar Feb 22 '24 00:02 ToddGrun

@333fred -- There is a change under compilers in this PR. However, I didn't end up using the refactored method (as the ImmutableSegmentedDictionary code can't reference that level). I think the change makes the modified method in compilers a bit cleaner, and it might be nice to expose such a method, but I can revert that part of the change if you'd prefer for that to not be included.

ToddGrun avatar Feb 23 '24 04:02 ToddGrun

Based on speedometer results, moving this out of draft status. @sharwell / @CyrusNajmabadi, ptal. @sharwell -- would like to push for taking the ImmutableSegmentedDictionary as part of this PR, and work with you on determining if a followup PR would be good in that area.

Test insertion PR here Speedometer results: here

Speedometer: Test method: CompletionTest.Completion Scenario: 9990.Totals Counter: CLR_BytesAllocated_NonDevenv

Original: ~1.9 GB allocated under SolutionCompilationState.UpdateDocumentState New: ~500 MB allocated under SolutionCompilationState.UpdateDocumentState

image

ToddGrun avatar Feb 23 '24 06:02 ToddGrun

I can look at the compilation tracker part tomorrow!

CyrusNajmabadi avatar Feb 23 '24 06:02 CyrusNajmabadi

@ToddGrun let's keep it out; I'd ask you to depend on TryGetNonEnumeratedCount on the appropriate TFMs anyways, so it's not like it would be an immediate no-feedback approval anyways.

333fred avatar Feb 23 '24 18:02 333fred

Done with review pass for changes under Compilers (commit 5)

AlekseyTs avatar Feb 23 '24 18:02 AlekseyTs