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 observed in local trace opening Roslyn.sln #68076

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

Conversation

sharwell
Copy link
Member

@sharwell sharwell commented May 3, 2023

sharwell added 5 commits May 3, 2023 12:19
This CI definition should have the same default queue as
roslyn-integration-CI.
Addresses 200MB of Large Object Heap allocations (40% of total LOH
allocations) observed in a local trace loading Roslyn.sln.
Resolves 150MB allocations observed in a local 50 second trace opening
Roslyn.sln.
Avoids 116MB allocations in a local 50 second performance trace opening
Roslyn.sln.
Fixes 6.8MB allocations observed in a 50 second trace opening Roslyn.sln.
@sharwell sharwell requested review from a team as code owners May 3, 2023 20:05
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 3, 2023
return IsTypeLessVisibleThan(type1, arg.sym, ref localUseSiteInfo);
},
(sym, localUseSiteInfoPtr),
canDigThroughNullable: true); // System.Nullable is public
Copy link
Member Author

Choose a reason for hiding this comment

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

⚠️ 🐉 Pay close attention to this change.

/cc @stephentoub

{
CompoundUseSiteInfo<AssemblySymbol> localUseSiteInfo = useSiteInfo;
var result = type.VisitType((type1, symbol, unused) => IsTypeLessVisibleThan(type1, symbol, ref localUseSiteInfo), sym,
canDigThroughNullable: true); // System.Nullable is public
var localUseSiteInfoPtr = (nint)Unsafe.AsPointer(ref localUseSiteInfo);
Copy link
Contributor

Choose a reason for hiding this comment

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

var localUseSiteInfoPtr = (nint)Unsafe.AsPointer(ref localUseSiteInfo);

I am curious how much does this specific change save and how does it affect CPU time.

Copy link
Member Author

Choose a reason for hiding this comment

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

It saves 150MB allocations over 50 seconds (also mentioned in the commit message).

Copy link
Contributor

@AlekseyTs AlekseyTs May 3, 2023

Choose a reason for hiding this comment

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

It saves 150MB allocations over 50 seconds (also mentioned in the commit message).

Sorry, I am having trouble translating this into user observable terms.

Copy link
Member Author

Choose a reason for hiding this comment

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

I noticed the IDE going slow opening Roslyn.sln, so I took a performance trace. Much of the CPU usage was in GC. When this was combined with high overall allocation rates, it suggested that the best course of action would be take a pass at reducing allocations that occurred during this trace. This was one of the allocations that was more easily addressed, in terms of it being a fairly localized change.

Copy link
Contributor

@AlekseyTs AlekseyTs May 4, 2023

Choose a reason for hiding this comment

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

This was one of the allocations that was more easily addressed, in terms of it being a fairly localized change.

Has this change, on its own, made any noticeable impact on the scenario? And I am not talking about number of allocations in the trace,

Copy link
Member Author

@sharwell sharwell May 4, 2023

Choose a reason for hiding this comment

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

I have no reason to believe so, even though the evidence suggests this was a small contributing factor to the much larger picture. I was only able to address 1% of the scenario allocations in the time box. However, over time we would hope that the incremental improvements would accumulate to the point of being observable.

{
CompoundUseSiteInfo<AssemblySymbol> localUseSiteInfo = useSiteInfo;
var result = type.VisitType((type1, symbol, unused) => IsTypeLessVisibleThan(type1, symbol, ref localUseSiteInfo), sym,
canDigThroughNullable: true); // System.Nullable is public
var localUseSiteInfoPtr = (nint)Unsafe.AsPointer(ref localUseSiteInfo);
Copy link
Contributor

Choose a reason for hiding this comment

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

var localUseSiteInfoPtr = (nint)Unsafe.AsPointer(ref localUseSiteInfo);

If we decide that we are comfortable going with this unsafe gymnastics, we should be able to get rid of the localUseSiteInfo local. It was added so that we could capture it in a closure.

Copy link
Member Author

Choose a reason for hiding this comment

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

The ref argument isn't guaranteed to be on the stack, so eliminating the local adds new gymnastics of a fixed statement (which ends up declaring a pointer to a non-blittable type and gives CS8500).

@jaredpar jaredpar added this to the 17.8 milestone Jul 18, 2023
@jaredpar jaredpar modified the milestones: 17.8, Backlog Sep 26, 2023
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.

5 participants