-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 ComputeReverseReferencesMap #76417
Reduce allocations again in ComputeReverseReferencesMap #76417
Conversation
Speedometer results from the last PR didn't improve allocations in the ProjectDependencyGraph as much as I had hoped. This PR instead changes ComputeReverseReferencesMap to use pooled data structures and ImmutableHashSet.Builder to build up it's final result. The speedometer test is still showing about 100 MB of allocations in this method during typing, my hope is that this should cut that in about half. Will create a test insertion for validation.
Commit 1 Test insertion: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/598416 |
src/Workspaces/Core/Portable/Workspace/Solution/ProjectDependencyGraph.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Workspace/Solution/ProjectDependencyGraph.cs
Outdated
Show resolved
Hide resolved
src/Workspaces/Core/Portable/Workspace/Solution/ProjectDependencyGraph.cs
Outdated
Show resolved
Hide resolved
2) Increase pool size from 128 to 256 as that's not an uncommon number of projects
return KeyValuePairUtil.Create(kvp.Key, reverseReferencesForProject); | ||
}) | ||
.ToImmutableDictionary(); | ||
return reverseReferencesMap.ToImmutableDictionary(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
poooled dict, to immutable dict? shouldn't this just be an ImmutableDictBuilder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be, but the builder is a class itself, so this avoids that allocation. I can switch to that though if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
teh main concern here is that to go from Dict to ImmutableDict you are rehashing everything.
Note: you could pool the ImmutableDictBuilder if you want to save that allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll just switch to an ImmutableDictBuilder here and see what the test insertion says.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Insertions says the allocation of the dictionary builder vs using a pooled dictionary doesn't show up, so we'll just go with this approach
Commit 3 test insertion: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/598548 |
Speedometer results from the last PR didn't improve allocations in the ProjectDependencyGraph as much as I had hoped. This PR instead changes ComputeReverseReferencesMap to use pooled data structures and ImmutableHashSet.Builder to build up it's final result.
The speedometer test is still showing about 100 MB of allocations in this method during typing, my hope is that this should cut that in about half. Will create a test insertion for validation.
*** allocations that are being targeted by this PR ***
![image](https://private-user-images.githubusercontent.com/6785178/395575879-7d40e4f5-adf9-4311-84d9-99518f4a4b18.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MTUxNDQsIm5iZiI6MTczOTYxNDg0NCwicGF0aCI6Ii82Nzg1MTc4LzM5NTU3NTg3OS03ZDQwZTRmNS1hZGY5LTQzMTEtODRkOS05OTUxOGY0YTRiMTgucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTVUMTAyMDQ0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NDdhMDc0NjkzNGMzODhiYWU3ZmJlYmVmNzAwNzBjNTIyMmNkZmE4ZWFjYjBkYmUxMmI1ODI2MzFhYWUxZGY0ZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.CD3n65V82UKmvPahZsJ3QQygcYN3EiAC_uWeip4vMl4)