-
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 observed in local trace opening Roslyn.sln #68076
base: main
Are you sure you want to change the base?
Changes from all commits
82b2b5d
ae6163a
0c33184
7a4d260
87080ad
054298d
403fd8c
add7590
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
using System.Collections.Immutable; | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using Microsoft.CodeAnalysis.PooledObjects; | ||
using Roslyn.Utilities; | ||
|
@@ -606,11 +607,18 @@ public static SpecialType GetSpecialTypeSafe(this TypeSymbol? type) | |
return type is object ? type.SpecialType : SpecialType.None; | ||
} | ||
|
||
public static bool IsAtLeastAsVisibleAs(this TypeSymbol type, Symbol sym, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo) | ||
public static unsafe bool IsAtLeastAsVisibleAs(this TypeSymbol type, Symbol sym, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo) | ||
{ | ||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
var result = type.VisitType( | ||
static (type1, arg, _) => | ||
{ | ||
ref var localUseSiteInfo = ref Unsafe.AsRef<CompoundUseSiteInfo<AssemblySymbol>>((void*)arg.localUseSiteInfoPtr); | ||
return IsTypeLessVisibleThan(type1, arg.sym, ref localUseSiteInfo); | ||
}, | ||
(sym, localUseSiteInfoPtr), | ||
canDigThroughNullable: true); // System.Nullable is public | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /cc @stephentoub |
||
useSiteInfo = localUseSiteInfo; | ||
return result is null; | ||
} | ||
|
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 am curious how much does this specific change save and how does it affect CPU time.
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 saves 150MB allocations over 50 seconds (also mentioned in the commit message).
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.
Sorry, I am having trouble translating this into user observable terms.
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 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.
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.
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,
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 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.