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

Pool the simplifiers we use when simplifying code. #19424

Merged
merged 6 commits into from
May 11, 2017

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented May 11, 2017

This is a followup to #19419

@@ -178,89 +178,92 @@ protected virtual SyntaxNode TransformReducedNode(SyntaxNode reducedNode, Syntax
{
var nodeOrTokenToReduce = nodesAndTokensToReduce[i];
simplifyTasks[i] = Task.Run(async () =>
{
var nodeOrToken = nodeOrTokenToReduce.OriginalNodeOrToken;
Copy link
Member Author

Choose a reason for hiding this comment

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

All this code stays the same. it just got indented. I will point out what actually changed.

}
using (var rewriter = reducer.GetOrCreateRewriter())
{
rewriter.Initialize(optionSet, cancellationToken);
Copy link
Member Author

Choose a reason for hiding this comment

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

these three lines are new. We now get a potentially pooled rewriter, and we initialize it with the current state.

Copy link
Member Author

Choose a reason for hiding this comment

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

Everything else in this file is just indentation.

@CyrusNajmabadi
Copy link
Member Author

Tagging @MattGertz

This lowered the amount of garbage i saw produced in a 'simplify all' scenario by several hundred MB on a large project. This was specifically where i marked the root of a document with the Simplification annotation and went and looked for all things that could be simplified.

The saving comes in two forms:

  1. Reduction of delegate allocations that we were creating on each node we were examining.
  2. Pooling of the "reducer" objects we use that we process each node with. For each node we wanted to simplify (potentially thousands ot millions) we were creating N simplifiers. A huge amount of garbage created.

@CyrusNajmabadi CyrusNajmabadi merged commit fa407a6 into dotnet:master May 11, 2017
@CyrusNajmabadi CyrusNajmabadi deleted the poolSimplifiers branch May 11, 2017 17:03
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Simplification;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp.Simplification
Copy link
Member

Choose a reason for hiding this comment

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

❕ Namespace should be updated to reflect new location

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.

5 participants