未验证 提交 064817dc 编写于 作者: M Manish Vasani 提交者: GitHub

Merge pull request #39395 from mavasani/FixCachingCFG

Performance fix in analyzer driver for CFG based analyzers
......@@ -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);
}
}
}
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册