-
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 closures allocated during invocation of CapturedSymbolReplacement.Replacement #74258
Reduce closures allocated during invocation of CapturedSymbolReplacement.Replacement #74258
Conversation
…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)
src/Compilers/CSharp/Portable/Lowering/ClosureConversion/ClosureConversion.cs
Outdated
Show resolved
Hide resolved
@@ -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); |
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.
Would really prefer if these put arg
before makeFrame
.
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.
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? |
We keep procrastinating on fixing the ordering across the codebase. I'm just going to submit a PR to do it. |
@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. |
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 2)
OK, going to merge with this parameter ordering for now. |
…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 ...
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)