-
Notifications
You must be signed in to change notification settings - Fork 4k
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 TypeConversions
allocations by caching them in AssemblySymbol
#69040
Conversation
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs
Outdated
Show resolved
Hide resolved
@RikkiGibson @333fred @AlekseyTs Could I get a review on this? Thanks! |
{ | ||
if (_lazyTypeConversions is null) | ||
{ | ||
Interlocked.CompareExchange(ref _lazyTypeConversions, new TypeConversions(this), 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.
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.
@AlekseyTs I'm not following with this.
Some existing code used to do new TypeConversions(ContainingAssembly)
where ContainingAssembly
doesn't seem guaranteed to be corlib.
My theory is that it's the caller responsibility to call the property for the correct assembly.
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.
Some existing code used to do
new TypeConversions(ContainingAssembly)
whereContainingAssembly
doesn't seem guaranteed to be corlib.
My theory is that it's the caller responsibility to call the property for the correct assembly.
I think that was just an oversight (luckily there wasn't many call sites like that), and we were lucky that this didn't cause observable negative effects. For example, I see conversions doing this.corLibrary.GetDeclaredSpecialType(SpecialType.System_Delegate)
, GetDeclaredSpecialType
is supposed toi be called only on a core library.
We also should add an assert to ConversionsBase
to verify that corLibrary
is indeed a core library.
@Youssef1313 Would it be possible to split unrelated changes into separate PRs? |
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs
Outdated
Show resolved
Hide resolved
TypeConversions
, bool arrays, and HashSet<TypeWithAnnotations>
allocationsTypeConversions
allocations by caching them in AssemblySymbol
|
@@ -39,6 +40,8 @@ internal abstract class AssemblySymbol : Symbol, IAssemblySymbolInternal | |||
/// </summary> | |||
private AssemblySymbol _corLibrary; | |||
|
|||
private TypeConversions _lazyTypeConversions; |
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.
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.
@AlekseyTs I followed exactly what _lazySpecialTypes
is doing, but I'm not very confident that the overrides where I have throw ExceptionUtilities.Unreachable()
are indeed not reachable. Should I instead use CorLibrary.TypeConversions
instead of those throw ExceptionUtilities.Unreachable()
?
Done with review pass (commit 1) |
Done with review pass (commit 2) |
src/Compilers/CSharp/Portable/Symbols/MissingCorLibrarySymbol.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingAssemblySymbol.cs
Outdated
Show resolved
Hide resolved
@@ -12,6 +12,7 @@ | |||
using System.Linq; | |||
using System.Reflection; | |||
using System.Reflection.PortableExecutable; | |||
using System.Threading; |
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.
Is this using necessary? #Closed
Done with review pass (commit 6) |
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.
LGTM (commit 7)
@cston, @dotnet/roslyn-compiler For the second review |
src/Compilers/CSharp/Portable/Symbols/MetadataOrSourceAssemblySymbol.cs
Outdated
Show resolved
Hide resolved
Thanks @Youssef1313. |
Reduce
TypeConversions
allocations by caching this to the AssemblySymbol. Fixes #68997