提交 7de6607a 编写于 作者: S Sam Harwell

Avoid fast-path captures in GetSessionAnalysisScopeTask

Addresses 680MB allocations analyzing Roslyn.sln.
上级 d6bc4428
......@@ -5,6 +5,7 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Threading.Tasks;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Diagnostics
{
......@@ -57,6 +58,9 @@ public AnalyzerExecutionContext(DiagnosticAnalyzer analyzer)
/// </summary>
private ImmutableArray<SuppressionDescriptor> _lazySuppressionDescriptors = default(ImmutableArray<SuppressionDescriptor>);
[PerformanceSensitive(
"https://github.com/dotnet/roslyn/issues/26778",
AllowCaptures = false)]
public Task<HostSessionStartAnalysisScope> GetSessionAnalysisScopeTask(AnalyzerExecutor analyzerExecutor)
{
lock (_gate)
......@@ -67,15 +71,19 @@ public Task<HostSessionStartAnalysisScope> GetSessionAnalysisScopeTask(AnalyzerE
return _lazySessionScopeTask;
}
task = Task.Run(() =>
{
var sessionScope = new HostSessionStartAnalysisScope();
analyzerExecutor.ExecuteInitializeMethod(_analyzer, sessionScope);
return sessionScope;
}, analyzerExecutor.CancellationToken);
task = getSessionAnalysisScopeTaskSlow(this, analyzerExecutor);
_lazySessionScopeTask = task;
return task;
static Task<HostSessionStartAnalysisScope> getSessionAnalysisScopeTaskSlow(AnalyzerExecutionContext context, AnalyzerExecutor executor)
{
return Task.Run(() =>
{
var sessionScope = new HostSessionStartAnalysisScope();
executor.ExecuteInitializeMethod(context._analyzer, sessionScope);
return sessionScope;
}, executor.CancellationToken);
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册