Skip to content

Commit

Permalink
Merge pull request #39395 from mavasani/FixCachingCFG
Browse files Browse the repository at this point in the history
Performance fix in analyzer driver for CFG based analyzers
  • Loading branch information
mavasani authored Oct 21, 2019
2 parents fef3d37 + e8ca13d commit 064817d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2269,8 +2269,15 @@ void executeExecutableCodeActions()

if (!operationsToAnalyze.IsEmpty)
{
executeOperationsActions(operationsToAnalyze);
executeOperationsBlockActions(operationBlocksToAnalyze, operationsToAnalyze, codeBlockActions);
try
{
executeOperationsActions(operationsToAnalyze);
executeOperationsBlockActions(operationBlocksToAnalyze, operationsToAnalyze, codeBlockActions);
}
finally
{
AnalyzerExecutor.OnOperationBlockActionsExecuted(operationBlocksToAnalyze);
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/Compilers/Core/Portable/DiagnosticAnalyzer/AnalyzerExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Runtime.CompilerServices;
using System.Threading;
using Microsoft.CodeAnalysis.FlowAnalysis;
using Microsoft.CodeAnalysis.Operations;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
Expand Down Expand Up @@ -1913,5 +1914,22 @@ private bool IsAnalyzerSuppressedForSymbol(DiagnosticAnalyzer analyzer, ISymbol

return true;
}

public void OnOperationBlockActionsExecuted(ImmutableArray<IOperation> operationBlocks)
{
// Clear _lazyControlFlowGraphMap entries for each operation block after we have executed
// all analysis callbacks for the given operation blocks. This avoids holding onto them
// for the entire compilation lifetime.
// These control flow graphs are created on demand and shared between flow analysis based analyzers.

if (_lazyControlFlowGraphMap?.Count > 0)
{
foreach (var operationBlock in operationBlocks)
{
var root = operationBlock.GetRootOperation();
_lazyControlFlowGraphMap.TryRemove(root, out _);
}
}
}
}
}

0 comments on commit 064817d

Please sign in to comment.