-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Investigate Blazor WebAssembly startup performance characteristics #54353
Comments
Currently, when using Blazor in InteractiveAuto render mode, the application starts with Blazor Server on the initial load and transitions to WebAssembly once all DLLs are loaded and cached. However, on subsequent requests, it waits for WebAssembly to start, neglecting the benefits of Blazor Server. To enhance performance and user experience, I suggest implementing a mechanism where the first page load or any subsequent refreshes always utilize Blazor Server, while booting WebAssembly in the background. This approach can mitigate concerns about WebAssembly startup performance, as we can improve it up to a certain extent. Making this behavior configurable would provide flexibility. Users could choose to wait for WebAssembly to load when the cache is available or opt for Blazor Server on every initial request, even if WebAssembly is downloaded. By implementing this approach, we can optimize the application's performance and provide users with a smoother transition to WebAssembly while still leveraging the benefits of Blazor Server where applicable. Would love to hear thoughts and feedback on this proposal! |
Bringing #31877 into the current milestone as @MackinnonBuck 's investigation leads us to believe that this work will bring substantial benefits to startup perf. |
Here are some results from this investigation:
By adding the following to the WebAssembly project's <PropertyGroup>
<WasmProfilers>browser;</WasmProfilers>
<WasmBuildNative>true</WasmBuildNative>
</PropertyGroup> ...and adding the following to the configureRuntime: (builder) => {
builder.withConfig({
browserProfilerOptions: {},
});
} ...a recording can be taken in the browser's dev tools "performance" tab and a flame graph will show how long each procedure takes.
One of the main contributors to startup time was reflection performed during JSON serialization. This indicated that using the STJ source generator may yield performance benefits.
In addition to existing Blazor WebAssembly standalone perf tests, we added automated Lighthouse tests earlier this year to see how changes like this affect Lighthouse metrics. After introducing a change that utilized the STJ source generator during WebAssembly startup, we noticed a WebAssembly startup time improvement of 15-30%. These numbers may vary for larger apps, or apps that do significant work in user code during startup. Finding a way to eliminate JSON serialization altogether during startup may result in further improvement of startup time (I would conservatively estimate an additional 15% improvement, possibly higher for Blazor Web scenarios because it performs more serialization on startup). Closing this issue out since the investigation is complete, and we have taken some steps to improve WebAssembly startup performance. We can open other issues to track additional improvements to WebAssembly startup. |
Even when Blazor WebAssembly assets are cached, the time it takes for a Blazor WebAssembly app to initialize can be significant. We should investigate ways to further optimize Blazor WebAssembly initialization to reduce this startup time.
Some preliminary investigation suggests that Blazor-specific startup (everything that happens after the code in
Program.cs
starts executing) accounts for at least half the total initialization time.We should:
Related issues:
The text was updated successfully, but these errors were encountered: