Skip to content

Reduce closures allocated during invocation of CapturedSymbolReplacement.Replacement#74258

Merged
ToddGrun merged 2 commits intodotnet:mainfrom
ToddGrun:dev/toddgrun/ReduceClosuresInvoking_CapturedSymbolReplacement_Replacement
Jul 5, 2024
Merged

Reduce closures allocated during invocation of CapturedSymbolReplacement.Replacement#74258
ToddGrun merged 2 commits intodotnet:mainfrom
ToddGrun:dev/toddgrun/ReduceClosuresInvoking_CapturedSymbolReplacement_Replacement

Conversation

@ToddGrun
Copy link
Contributor

@ToddGrun ToddGrun commented Jul 3, 2024

This method previously took in a Func<NamedTypeSymbol, BoundExpression> and most callers allocated a closure to implement the callback. This PR uses the args pattern and adds a parameter to the Replacement method that is passed back into that callback to better allow static lambdas to be used.

This was the top allocating closure allocation in vbcscompiler in a customer profile I'm looking at (0.2% -- 42 MB)

image

…ent.Replacement

This method previously took in a Func<NamedTypeSymbol, BoundExpression> and most callers allocated a closure to implement the callback. This PR uses the args pattern and adds a parameter to the Replacement method that is passed back into that callback to better allow static lambdas to be used.

This was the top allocating closure allocation in vbcscompiler in a customer profile I'm looking at (0.2% -- 42 MB)
@ToddGrun ToddGrun requested a review from a team as a code owner July 3, 2024 15:32
@ghost ghost added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 3, 2024
/// of the appropriate frame.
/// </summary>
public abstract BoundExpression Replacement(SyntaxNode node, Func<NamedTypeSymbol, BoundExpression> makeFrame);
public abstract BoundExpression Replacement<TArg>(SyntaxNode node, Func<NamedTypeSymbol, TArg, BoundExpression> makeFrame, TArg arg);
Copy link
Member

Choose a reason for hiding this comment

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

Would really prefer if these put arg before makeFrame.

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

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

Not going to block on it, but would prefer if we made the args more developer-friendly.

@ToddGrun
Copy link
Contributor Author

ToddGrun commented Jul 3, 2024

Not going to block on it, but would prefer if we made the args more developer-friendly.

I'm flexible on this, although it's a bit unfortunate for the compilers and editor folks to have different orderings. How about, I'll go with whatever the other compiler dev indicates is there desire for the ordering?

@333fred
Copy link
Member

333fred commented Jul 3, 2024

I'm flexible on this, although it's a bit unfortunate for the compilers and editor folks to have different orderings.

We keep procrastinating on fixing the ordering across the codebase. I'm just going to submit a PR to do it.

@sharwell
Copy link
Contributor

sharwell commented Jul 3, 2024

@333fred another problems is the lambda being first is the way public APIs are written in the .NET libraries. It might be better to fix the experience for that than to make up a different pattern from everyone else.

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 2)

@ToddGrun
Copy link
Contributor Author

ToddGrun commented Jul 5, 2024

OK, going to merge with this parameter ordering for now.

@ToddGrun ToddGrun merged commit 4dbedf6 into dotnet:main Jul 5, 2024
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 5, 2024
333fred added a commit to 333fred/roslyn that referenced this pull request Jul 9, 2024
…solution-priority

* upstream/main: (184 commits)
  Disable BuildWithNetFrameworkHostedCompiler (dotnet#74299)
  Avoid using constants for large string literals (dotnet#74305)
  Adjust lowering of a string interpolation in an expression lambda to not use expanded non-array `params` collection in Format/Create calls. (dotnet#74274)
  Consolidate test Span sources (dotnet#74281)
  Allow Document.FilePath to be set to null (dotnet#74290)
  Update Directory.Build.rsp
  Remove fallback options from IdeAnalyzerOptions (dotnet#74235)
  Fix msbuild issue
  Improve parser recovery around nullable types in patterns (dotnet#72805)
  Syntax formatting options (dotnet#74223)
  Localized file check-in by OneLocBuild Task: Build definition ID 327: Build ID 2490585 (dotnet#74287)
  fix (dotnet#74276)
  Remove more
  fix (dotnet#74237)
  Fix scenario where lightbulbs weren't being displayed
  Reduce closures allocated during invocation of CapturedSymbolReplacement.Replacement (dotnet#74258)
  Reduce allocations in SymbolDeclaredCompilationEvent (dotnet#74250)
  remove type that now serves no purpose
  Remove uncalled method
  Remove more unused code
  ...
@RikkiGibson RikkiGibson modified the milestones: Next, 17.12 P1 Jul 29, 2024
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