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 closures allocated during invocation of CapturedSymbolReplacement.Replacement #74258

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
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 3, 2024
@@ -23,7 +23,7 @@ public CapturedSymbolReplacement(bool isReusable)
/// Rewrite the replacement expression for the hoisted local so all synthesized field are accessed as members
/// 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
Member

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
24 checks passed
@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