-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Add console runner for measuring Blazor perf on desktop interpreter #24469
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
SteveSandersonMS
merged 1 commit into
master
from
stevesa/add-blazor-perf-console-runner
Aug 3, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/Components/benchmarkapps/Wasm.Performance/ConsoleHost/ConsoleHostRenderer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Runtime.ExceptionServices; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Components; | ||
using Microsoft.AspNetCore.Components.RenderTree; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Wasm.Performance.ConsoleHost | ||
{ | ||
internal class ConsoleHostRenderer : Renderer | ||
{ | ||
public ConsoleHostRenderer(IServiceProvider serviceProvider, ILoggerFactory loggerFactory) | ||
: base(serviceProvider, loggerFactory) | ||
{ | ||
} | ||
|
||
public override Dispatcher Dispatcher { get; } = new NullDispatcher(); | ||
|
||
protected override void HandleException(Exception exception) | ||
{ | ||
ExceptionDispatchInfo.Capture(exception).Throw(); | ||
} | ||
|
||
protected override Task UpdateDisplayAsync(in RenderBatch renderBatch) | ||
{ | ||
// ConsoleHost is only for profiling the .NET side of execution. | ||
// There isn't a real display to update. | ||
return Task.CompletedTask; | ||
} | ||
|
||
// Expose some protected APIs publicly | ||
public new int AssignRootComponentId(IComponent component) | ||
=> base.AssignRootComponentId(component); | ||
|
||
public new Task RenderRootComponentAsync(int componentId) | ||
=> base.RenderRootComponentAsync(componentId); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Components/benchmarkapps/Wasm.Performance/ConsoleHost/NullDispatcher.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace Wasm.Performance.ConsoleHost | ||
{ | ||
internal class NullDispatcher : Dispatcher | ||
{ | ||
public override bool CheckAccess() | ||
=> true; | ||
|
||
public override Task InvokeAsync(Action workItem) | ||
{ | ||
workItem(); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public override Task InvokeAsync(Func<Task> workItem) | ||
=> workItem(); | ||
|
||
public override Task<TResult> InvokeAsync<TResult>(Func<TResult> workItem) | ||
=> Task.FromResult(workItem()); | ||
|
||
public override Task<TResult> InvokeAsync<TResult>(Func<Task<TResult>> workItem) | ||
=> workItem(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Components/benchmarkapps/Wasm.Performance/ConsoleHost/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.Extensions.CommandLineUtils; | ||
using Wasm.Performance.ConsoleHost.Scenarios; | ||
|
||
namespace Wasm.Performance.ConsoleHost | ||
{ | ||
internal class Program : CommandLineApplication | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
new Program().Execute(args); | ||
} | ||
|
||
public Program() | ||
{ | ||
OnExecute(() => | ||
{ | ||
ShowHelp(); | ||
return 1; | ||
}); | ||
|
||
Commands.Add(new GridScenario()); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ts/benchmarkapps/Wasm.Performance/ConsoleHost/Scenarios/ComponentRenderingScenarioBase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.CommandLineUtils; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Wasm.Performance.ConsoleHost.Scenarios | ||
{ | ||
internal abstract class ComponentRenderingScenarioBase : CommandLineApplication | ||
{ | ||
protected ComponentRenderingScenarioBase(string name) | ||
{ | ||
Name = name; | ||
|
||
var cyclesOption = new CommandOption("--cycles", CommandOptionType.SingleValue); | ||
Options.Add(cyclesOption); | ||
|
||
OnExecute(() => | ||
{ | ||
var numCycles = cyclesOption.HasValue() ? int.Parse(cyclesOption.Value()) : 1; | ||
|
||
var serviceCollection = new ServiceCollection(); | ||
PopulateServiceCollection(serviceCollection); | ||
var serviceProvider = serviceCollection.BuildServiceProvider(); | ||
|
||
var loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>(); | ||
var renderer = new ConsoleHostRenderer(serviceProvider, loggerFactory); | ||
|
||
var startTime = DateTime.Now; | ||
ExecuteAsync(renderer, numCycles).Wait(); | ||
|
||
var duration = DateTime.Now - startTime; | ||
var durationPerCycle = (duration / numCycles).TotalMilliseconds; | ||
Console.WriteLine($"{Name}: {durationPerCycle:F1}ms per cycle (cycles tested: {numCycles})"); | ||
|
||
return 0; | ||
}); | ||
} | ||
|
||
protected virtual void PopulateServiceCollection(IServiceCollection serviceCollection) | ||
{ | ||
serviceCollection.AddLogging(); | ||
} | ||
|
||
protected abstract Task ExecuteAsync(ConsoleHostRenderer renderer, int numCycles); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Components/benchmarkapps/Wasm.Performance/ConsoleHost/Scenarios/GridScenario.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.CommandLineUtils; | ||
using Wasm.Performance.TestApp.Pages; | ||
|
||
namespace Wasm.Performance.ConsoleHost.Scenarios | ||
{ | ||
internal class GridScenario : ComponentRenderingScenarioBase | ||
{ | ||
readonly CommandOption _gridTypeOption = new CommandOption("--gridtype", CommandOptionType.SingleValue); | ||
|
||
public GridScenario() : base("grid") | ||
{ | ||
Options.Add(_gridTypeOption); | ||
} | ||
|
||
protected override async Task ExecuteAsync(ConsoleHostRenderer renderer, int numCycles) | ||
{ | ||
var gridType = _gridTypeOption.HasValue() | ||
? (GridRendering.RenderMode)Enum.Parse(typeof(GridRendering.RenderMode), _gridTypeOption.Value(), true) | ||
: GridRendering.RenderMode.FastGrid; | ||
|
||
for (var i = 0; i < numCycles; i++) | ||
{ | ||
var hostPage = new GridRendering { SelectedRenderMode = gridType }; | ||
hostPage.Show(); | ||
|
||
var componentId = renderer.AssignRootComponentId(hostPage); | ||
await renderer.RenderRootComponentAsync(componentId); | ||
|
||
hostPage.ChangePage(); | ||
await renderer.RenderRootComponentAsync(componentId); | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...Components/benchmarkapps/Wasm.Performance/ConsoleHost/Wasm.Performance.ConsoleHost.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<IsShipping>false</IsShipping> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\TestApp\Wasm.Performance.TestApp.csproj" /> | ||
<Compile Include="$(SharedSourceRoot)CommandLineUtils\**\*.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This event handler logic change has no impact on the benchmarks because they never called this code anyway. I'm just clearing it up a bit.