提交 e8ca13dd 编写于 作者: M Manish Vasani

Performance fix in analyzer driver for CFG based analyzers.

We expose public APIs on IOperation related analysis contexts to fetch ControlFlowGraph for the operation block. Additionally, the analyzer driver caches the CFGs for operation block (when first requested by some flow based analyzer) to allow sharing CFGs between flow based analyzers. However, we were holding onto these for the entire lifetime of the compilation. This change fixes that by removing the CFG entry once a particular operation block has been fully analyzed.

Fixes VSFeedback issue [#998181](https://dev.azure.com/devdiv/DevDiv/_workitems/edit/998181)
上级 02d1b3cc
......@@ -2259,8 +2259,15 @@ void executeExecutableCodeActions()
if (!operationsToAnalyze.IsEmpty)
{
executeOperationsActions(operationsToAnalyze);
executeOperationsBlockActions(operationBlocksToAnalyze, operationsToAnalyze, codeBlockActions);
try
{
executeOperationsActions(operationsToAnalyze);
executeOperationsBlockActions(operationBlocksToAnalyze, operationsToAnalyze, codeBlockActions);
}
finally
{
AnalyzerExecutor.OnOperationBlockActionsExecuted(operationBlocksToAnalyze);
}
}
}
......
......@@ -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;
......@@ -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 _);
}
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册