提交 fce2c4a2 编写于 作者: S Sam Harwell

Use ValueTask<T> on allocation hot paths where operations normally complete synchronously

上级 3a852e00
......@@ -74,7 +74,8 @@ public AnalyzerManager(DiagnosticAnalyzer analyzer)
}
}
private async Task<HostSessionStartAnalysisScope> GetSessionAnalysisScopeAsync(
[PerformanceSensitive("https://github.com/dotnet/roslyn/issues/23582", OftenCompletesSynchronously = true)]
private async ValueTask<HostSessionStartAnalysisScope> GetSessionAnalysisScopeAsync(
DiagnosticAnalyzer analyzer,
AnalyzerExecutor analyzerExecutor)
{
......@@ -82,7 +83,8 @@ public AnalyzerManager(DiagnosticAnalyzer analyzer)
return await GetSessionAnalysisScopeCoreAsync(analyzer, analyzerExecutor, analyzerExecutionContext).ConfigureAwait(false);
}
private async Task<HostSessionStartAnalysisScope> GetSessionAnalysisScopeCoreAsync(
[PerformanceSensitive("https://github.com/dotnet/roslyn/issues/23582", OftenCompletesSynchronously = true)]
private async ValueTask<HostSessionStartAnalysisScope> GetSessionAnalysisScopeCoreAsync(
DiagnosticAnalyzer analyzer,
AnalyzerExecutor analyzerExecutor,
AnalyzerExecutionContext analyzerExecutionContext)
......@@ -108,7 +110,8 @@ public AnalyzerManager(DiagnosticAnalyzer analyzer)
/// The returned actions include the actions registered during <see cref="DiagnosticAnalyzer.Initialize(AnalysisContext)"/> method as well as
/// the actions registered during <see cref="CompilationStartAnalyzerAction"/> for the given compilation.
/// </summary>
public async Task<AnalyzerActions> GetAnalyzerActionsAsync(DiagnosticAnalyzer analyzer, AnalyzerExecutor analyzerExecutor)
[PerformanceSensitive("https://github.com/dotnet/roslyn/issues/23582", OftenCompletesSynchronously = true)]
public async ValueTask<AnalyzerActions> GetAnalyzerActionsAsync(DiagnosticAnalyzer analyzer, AnalyzerExecutor analyzerExecutor)
{
var sessionScope = await GetSessionAnalysisScopeAsync(analyzer, analyzerExecutor).ConfigureAwait(false);
if (sessionScope.CompilationStartActions.Length > 0 && analyzerExecutor.Compilation != null)
......
......@@ -138,12 +138,13 @@ public static string GetAnalyzerAssemblyName(this DiagnosticAnalyzer analyzer)
return typeInfo.Assembly.GetName().Name;
}
public static Task<OptionSet> GetDocumentOptionSetAsync(this AnalyzerOptions analyzerOptions, SyntaxTree syntaxTree, CancellationToken cancellationToken)
[PerformanceSensitive("https://github.com/dotnet/roslyn/issues/23582", OftenCompletesSynchronously = true)]
public static ValueTask<OptionSet> GetDocumentOptionSetAsync(this AnalyzerOptions analyzerOptions, SyntaxTree syntaxTree, CancellationToken cancellationToken)
{
var workspaceAnalyzerOptions = analyzerOptions as WorkspaceAnalyzerOptions;
if (workspaceAnalyzerOptions == null)
{
return SpecializedTasks.Default<OptionSet>();
return new ValueTask<OptionSet>(default(OptionSet));
}
return workspaceAnalyzerOptions.GetDocumentOptionSetAsync(syntaxTree, cancellationToken);
......
......@@ -3,12 +3,14 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Simplification;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles
{
internal static class SymbolAnalysisContextExtensions
{
public static async Task<NamingStylePreferences> GetNamingStylePreferencesAsync(
[PerformanceSensitive("https://github.com/dotnet/roslyn/issues/23582", OftenCompletesSynchronously = true)]
public static async ValueTask<NamingStylePreferences> GetNamingStylePreferencesAsync(
this SymbolAnalysisContext context)
{
var location = context.Symbol.Locations.FirstOrDefault();
......
......@@ -26,7 +26,8 @@ public WorkspaceAnalyzerOptions(AnalyzerOptions options, OptionSet optionSet, So
public HostWorkspaceServices Services => _solution.Workspace.Services;
public async Task<OptionSet> GetDocumentOptionSetAsync(SyntaxTree syntaxTree, CancellationToken cancellationToken)
[PerformanceSensitive("https://github.com/dotnet/roslyn/issues/23582", OftenCompletesSynchronously = true)]
public async ValueTask<OptionSet> GetDocumentOptionSetAsync(SyntaxTree syntaxTree, CancellationToken cancellationToken)
{
var documentId = _solution.GetDocumentId(syntaxTree);
if (documentId == null)
......
......@@ -179,7 +179,7 @@ public Task<SyntaxTree> GetSyntaxTreeAsync(CancellationToken cancellationToken =
}
// do it async for real.
return DocumentState.GetSyntaxTreeAsync(cancellationToken);
return DocumentState.GetSyntaxTreeAsync(cancellationToken).AsTask();
}
internal SyntaxTree GetSyntaxTreeSynchronously(CancellationToken cancellationToken)
......
......@@ -645,7 +645,8 @@ public bool TryGetSyntaxTree(out SyntaxTree syntaxTree)
return false;
}
public async Task<SyntaxTree> GetSyntaxTreeAsync(CancellationToken cancellationToken)
[PerformanceSensitive("https://github.com/dotnet/roslyn/issues/23582", OftenCompletesSynchronously = true)]
public async ValueTask<SyntaxTree> GetSyntaxTreeAsync(CancellationToken cancellationToken)
{
var treeAndVersion = await _treeSource.GetValueAsync(cancellationToken).ConfigureAwait(false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册