dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.36k stars 9.99k forks source link

Performance Regression in Blazor WebAssembly with .NET 9 #58507

Open Pvxtotal opened 2 days ago

Pvxtotal commented 2 days ago

Is there an existing issue for this?

Describe the bug

After upgrading to .NET 9 (including RC2), I've encountered significant performance issues in my Blazor Web App (WebAssembly Global). Specifically, the application frequently freezes for seconds before switching to Interactive WebAssembly mode. The overall application performance feels slower compared to .NET 8.

In some cases, the app remains frozen in SSR mode and never enters Interactive Mode. This behavior is consistent across different machines, so I believe it is not hardware-specific.

Reproduction Steps The app is built using the Blazor Web App template, configured for WebAssembly Global. Prerender is turned off. I've tested it across multiple machines with the same results using AMD Ryzen CPU.

The delay before entering Interactive Mode in .NET 9 is noticeably longer than in .NET 8. See the comparison below:

.NET 9 Demo: https://github.com/user-attachments/assets/bb4e30dc-90c6-4a26-9beb-f0b418ba5e9c

.NET 8 Demo: https://github.com/user-attachments/assets/7cc03af3-7219-4ba4-ba96-b73a1fa89c3d

While publishing with wasm-tools slightly improves performance, the delay before entering Interactive Mode is still present.

The issue persists regardless of whether I use Release or Debug modes.

Additional Information Environment: Debugging in Visual Studio 2022 Preview 17.12.0 with .NET 9 Blazor often crashes, leading to a poor debugging experience. Image

Request It would be helpful to know if others have experienced similar performance regressions or if there are any recommended workarounds or fixes in .NET 9 for this issue.

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

9.0.100-rc.2.24474.11

Anything else?

No response

Gabrieldsantos96 commented 2 days ago

Up

javiercn commented 1 day ago

@Pvxtotal thanks for contacting us.

It's not clear to us if you uploaded the same video twice, but we can't appreciate the regression that you are mentioning.

In order for us to get a better understanding of the problem you seem to be facing; can you use the Performance API to get precise numbers on performance?

It's also important to make sure that: 1) You are always testing in release mode. 2) You are running against the published app.

Pvxtotal commented 1 day ago

@Pvxtotal thanks for contacting us.

It's not clear to us if you uploaded the same video twice, but we can't appreciate the regression that you are mentioning.

In order for us to get a better understanding of the problem you seem to be facing; can you use the Performance API to get precise numbers on performance?

It's also important to make sure that:

  1. You are always testing in release mode.
  2. You are running against the published app.

Update:

After running tests using the Performance API in both Release Mode and Debug Mode, it seems the performance regression is only apparent in Debug Mode. Below are the detailed results, including the full JSON objects:

Release Mode Results:

In Release Mode, both .NET 8 and .NET 9 have similar performance, with no significant differences in the time taken to switch from SSR to Interactive Mode.

Debug Mode Results:

In Debug Mode, the performance in .NET 9 is noticeably slower compared to .NET 8, with durations increasing by around 500 ms in most cases.

Additional Observations:

While analyzing the videos, make sure you notice that the fonts and interactive assets (e.g., the Header component, the search bar) load significantly faster in .NET 8 compared to .NET 9. This is especially apparent in the .NET 8 video, where the fonts (loaded dynamically by a custom logic MainLayout.razor) and the interactive Header are fully loaded and displayed much earlier in the page load compared to .NET 9.

Conclusion:

It appears the performance issue is specific to Debug Mode. In Release Mode, both versions perform similarly, and there’s no major regression. However, Debug Mode in .NET 9 shows a clear degradation in the time it takes to enter Interactive Mode compared to .NET 8.

Please let me know if there are any additional steps you would like me to take to further investigate this issue.

Thank you for the support!