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

Use a singleton sentinel for empty type-parameters for non-generic named-types and methods. #68131

Merged
merged 13 commits into from
May 11, 2023

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented May 8, 2023

Small changes to address large heap usage of SourceNamedTypeSymbol and SourceOrdinaryMethodSymbol:

image

Takes us to:

image

Drops us 1.4%.

@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 8, 2023
@CyrusNajmabadi CyrusNajmabadi changed the title WIP: Use a singleton for empty type-parameters for named types Use a singleton sentinel for empty type-parameters for non-generic named-types and methods. May 8, 2023
@CyrusNajmabadi
Copy link
Member Author

@jaredpar ptal.

@@ -23,7 +23,6 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
/// </summary>
internal abstract class SourceOrdinaryMethodSymbolBase : SourceOrdinaryMethodOrUserDefinedOperatorSymbol
{
private readonly ImmutableArray<TypeParameterSymbol> _typeParameters;
Copy link
Member Author

Choose a reason for hiding this comment

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

methods were odd. _typeParameters was in SourceOrdinaryMethodSymbolBase (not SourceOrdinaryMethodSymbol), but was always empty for all other types. So this pushed this value down into SourceOrdinaryMethodSymbol, which could then use the new TypeParameterInfo object. All other methods just return 'Empty' from their TypeParameters helpers.

Note: this also ends up saving this extra pointer from all other source methods.

/// <summary>
/// Wrapper around type-parameter/constraints/constraint-kind info. We wrap this information (instead of inlining
/// directly within type/method symbols) as most types/methods are not generic. As such, all those non-generic
/// types can point at the singleton sentivel <see cref="Empty"/> value, and avoid two pointers of overhead.
Copy link
Member

@jcouv jcouv May 8, 2023

Choose a reason for hiding this comment

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

sentivel

typo: sentinel #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed!

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Done with review pass (iteration 6). Only minor comments

@jcouv jcouv self-assigned this May 9, 2023
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label May 9, 2023
@CyrusNajmabadi CyrusNajmabadi requested a review from jcouv May 9, 2023 00:54
@CyrusNajmabadi
Copy link
Member Author

@dotnet/roslyn-compiler @cston ptal

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 10)

@CyrusNajmabadi
Copy link
Member Author

@333fred @cston ptal.

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 10)

@CyrusNajmabadi
Copy link
Member Author

This is ready for review.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 13)

@CyrusNajmabadi CyrusNajmabadi merged commit 236149d into dotnet:main May 11, 2023
@CyrusNajmabadi CyrusNajmabadi deleted the namedTypeParams branch May 11, 2023 17:37
@ghost ghost added this to the Next milestone May 11, 2023
@Cosifne Cosifne modified the milestones: Next, 17.7 P2 May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants