Skip to content

Fix Blazor WebAssembly Hosted and Blazor Server build perf benchmarks #1943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 4 additions & 5 deletions build/build-perf-scenarios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ parameters:

- displayName: "Build - BlazorWasm"
arguments: --scenario blazorwasm $(buildJobs) --property scenario=BlazorWasm
# Skip https://github.com/dotnet/aspnetcore/issues/49760
# - displayName: "Build - BlazorWasm (Hosted)"
# arguments: --scenario blazorwasm-hosted $(buildJobs) --property scenario=BlazorWasmHosted
# - displayName: "Build - BlazorServer"
# arguments: --scenario blazorserver $(buildJobs) --property scenario=BlazorServer
- displayName: "Build - BlazorWasm (Hosted)"
arguments: --scenario blazorwasm-hosted $(buildJobs) --property scenario=BlazorWasmHosted
- displayName: "Build - BlazorServer"
arguments: --scenario blazorserver $(buildJobs) --property scenario=BlazorServer
- displayName: "Build - MVC"
arguments: --scenario mvc $(buildJobs) --property scenario=MVC
- displayName: "Build - API"
Expand Down
22 changes: 2 additions & 20 deletions src/BenchmarksApps/BuildPerformance/BlazorServerScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public BlazorServerScenario(DotNet dotnet)

public async Task RunAsync()
{
await _dotnet.ExecuteAsync($"new blazor --use-server");
await _dotnet.ExecuteAsync($"new blazor -int Server");

await Build();

Expand All @@ -35,9 +35,6 @@ public async Task RunAsync()
// No-Op build
await NoOpBuild();

// Changes to a .cshtml file
await ModifyCshtmlFile();

// Rebuild
await Rebuild();
}
Expand Down Expand Up @@ -68,7 +65,7 @@ async Task ChangeCSFile()

async Task ChangeToRazorMarkup()
{
var indexRazorFile = Path.Combine(_workingDirectory, "Components", "Pages", "Index.razor");
var indexRazorFile = Path.Combine(_workingDirectory, "Components", "Pages", "Home.razor");
File.AppendAllText(indexRazorFile, Environment.NewLine + "<h3>New content</h3>");

var buildDuration = await _dotnet.ExecuteAsync("build --no-restore");
Expand Down Expand Up @@ -117,20 +114,5 @@ async Task AddParameterToComponent()
buildDuration.TotalMilliseconds,
"Add a parameter to .razor");
}

async Task ModifyCshtmlFile()
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this because there are no .cshtml files in the template anymore.

{
var file = Path.Combine(_workingDirectory, "App.razor");
var originalContent = File.ReadAllText(file);

File.WriteAllText(file, originalContent.Replace("<body>", "<body><h2>Some text</h2>"));

var buildDuration = await _dotnet.ExecuteAsync("build --no-restore");

MeasureAndRegister(
"blazorserver/razor-change-cshtml",
buildDuration.TotalMilliseconds,
"Change .cshtml file markup");
}
}
}
27 changes: 6 additions & 21 deletions src/BenchmarksApps/BuildPerformance/BlazorWasmHosted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Build
{
class BlazorWasmHosted
{
private const string ProjectName = "BlazorApp";

private readonly DotNet _dotnet;
private readonly string _workingDirectory;
private readonly string _serverDirectory;
Expand All @@ -18,19 +20,16 @@ public BlazorWasmHosted(DotNet dotNet)
{
_dotnet = dotNet;
_workingDirectory = dotNet.WorkingDirectory;
_serverDirectory = Path.Combine(_workingDirectory, "Server");
_clientDirectory = Path.Combine(_workingDirectory, "Client");
_serverDirectory = Path.Combine(_workingDirectory, ProjectName);
_clientDirectory = Path.Combine(_workingDirectory, $"{ProjectName}.Client");
}

public async Task RunAsync()
{
await _dotnet.ExecuteAsync($"new blazor --use-wasm");
await _dotnet.ExecuteAsync($"new blazor -n {ProjectName} -o . -int WebAssembly");

await Build();

// Change
await ChangeShared();

// Changes to .razor file markup
await ChangeClient();

Expand Down Expand Up @@ -67,23 +66,9 @@ async Task ChangeServer()
"Change a file in Server");
}

async Task ChangeShared()
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed this because there is no "Shared" project anymore.

{
// Changes to .cs file
var csFile = Path.Combine(_workingDirectory, "Shared", "WeatherForecast.cs");
File.AppendAllText(csFile, Environment.NewLine + "// Hello world");

var buildDuration = await _dotnet.ExecuteAsync("build --no-restore", _serverDirectory);

MeasureAndRegister(
"blazorwasm-hosted/shared-file",
buildDuration.TotalMilliseconds,
"Change a file in shared");
}

async Task ChangeClient()
{
var indexRazorFile = Path.Combine(_clientDirectory, "Pages", "Index.razor");
var indexRazorFile = Path.Combine(_clientDirectory, "Pages", "Counter.razor");
File.AppendAllText(indexRazorFile, Environment.NewLine + "<h3>New content</h3>");

var buildDuration = await _dotnet.ExecuteAsync("build --no-restore", _serverDirectory);
Expand Down