Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public enum FileTypes
Large
}

[Params(0, 1, 1000)]
public static int N = 0;

[ParamsAllValues]
public FileTypes FileType { get; set; }

Expand All @@ -45,7 +48,7 @@ public async Task SetupAsync()
DocumentPullDiagnosticsEndpoint = new DocumentPullDiagnosticsEndpoint(
languageServerFeatureOptions: languageServer.GetRequiredService<LanguageServerFeatureOptions>(),
translateDiagnosticsService: languageServer.GetRequiredService<RazorTranslateDiagnosticsService>(),
languageServer: new ClientNotifierService());
languageServer: new ClientNotifierService(N));
var projectRoot = Path.Combine(RepoRoot, "src", "Razor", "test", "testapps", "ComponentApp");
var projectFilePath = Path.Combine(projectRoot, "ComponentApp.csproj");
_filePath = Path.Combine(projectRoot, "Components", "Pages", $"Generated.razor");
Expand Down Expand Up @@ -73,7 +76,7 @@ public async Task SetupAsync()

var diagnostics = await DocumentPullDiagnosticsEndpoint!.HandleRequestAsync(request, RazorRequestContext, CancellationToken.None);

if (!diagnostics!.ElementAtOrDefault(0)!.Diagnostics!.ElementAtOrDefault(0)!.Message.Contains("CallOnMe"))
if (N > 0 && !diagnostics!.ElementAtOrDefault(0)!.Diagnostics!.ElementAtOrDefault(0)!.Message.Contains("CallOnMe"))
{
throw new NotImplementedException("benchmark setup is wrong");
}
Expand Down Expand Up @@ -174,6 +177,13 @@ public override bool ReturnCodeActionAndRenamePathsWithPrefixedSlash

private class ClientNotifierService : ClientNotifierServiceBase
{
private readonly int _number;

public ClientNotifierService(int number)
{
_number = number;
}

public override Task OnInitializedAsync(VSInternalClientCapabilities clientCapabilities, CancellationToken cancellationToken)
{
return Task.CompletedTask;
Expand All @@ -191,30 +201,32 @@ public override Task SendNotificationAsync(string method, CancellationToken canc

public override Task<TResponse> SendRequestAsync<TParams, TResponse>(string method, TParams @params, CancellationToken cancellationToken)
{
object result = new RazorPullDiagnosticResponse(
var result = BuildDiagnostics(_number);
return Task.FromResult((TResponse)result);
}

private static object BuildDiagnostics(int numDiagnostics)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better if this method was called in the setup method, and the array passed directly to the ClientNotifierService. At the moment the benchmark is measuring the memory allocated by creating this array, which is likely to mask any improvements, and make identifying real problems harder.

{
return new RazorPullDiagnosticResponse(
new[]
{
new VSInternalDiagnosticReport()
{
ResultId = "5",
Diagnostics = new Diagnostic[]
Diagnostics = Enumerable.Range(1000, numDiagnostics).Select(x => new Diagnostic
{
new()
{
Range = new Range()
{
Start = new Position(10, 19),
End = new Position(10, 23)
},
Code = "CS0103",
Code = "CS" + x,
Severity = DiagnosticSeverity.Error,
Source = "DocumentPullDiagnosticHandler",
Message = "The name 'CallOnMe' does not exist in the current context"
}
}
}).ToArray()
}
}, Array.Empty<VSInternalDiagnosticReport>());
return Task.FromResult((TResponse)result);
}
}
}