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.45k stars 10.03k forks source link

Ability to use System.Text.Json's generated sources to improve PersistentComponentState's json read performance #40683

Open ysmoradi opened 2 years ago

ysmoradi commented 2 years ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

No response

Describe the solution you'd like

PersistentComponentState's TryTakeFromJson method uses System.Text.Json's auto generated sources of JsonSerializerContext & JsonSerializable I'd like to use something like what asp.net core web API has as followings:

services
            .AddControllers...
            .AddJsonOptions(options => options.JsonSerializerOptions.AddContext<MyAppJsonContext>());

So aspnet core web API uses MyAppJsonContext globally to improve its performance. I'd like to use generated sources of System.Text.Json in client side to read transferred json state

Currently blazor uses JsonSerializerOptionsProvider which is internal and we can't call .AddContext() to make sure it has access to our source generator based context

Additional context

No response

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ysmoradi commented 1 year ago

I understand that you have a lot of work, but given its simplicity, it can greatly affect the startup time. Do we have an update on this? Will it reach dotnet 8?

ghost commented 10 months ago

Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

mkArtakMSFT commented 10 months ago

Related https://github.com/dotnet/aspnetcore/issues/31877

ysmoradi commented 10 months ago

While it's possible to defer this issue to even .NET 17 planning(!), this approach is not appropriate. This is not a critical blocking bug that a large number of people are expected to comment to determining its priority. While developers are aware of Blazor WebAssembly's slow startup time, especially on Android devices, they may not fully comprehend the underlying causes.

The significant performance boost provided by System.Text.Json Source Generators is evident based on Microsoft's own data, and it's more beneficial in Blazor WebAssembly, which lacks JIT compilation.

Currently, developers can customize their JSON options in ASP.NET Core MVC Restful API and ASP.NET Core Minimal API projects but not in Blazor applications! This omission negatively impacts performance, particularly in the Blazor WebAssembly Startup phase of pre rendered websites and JSRuntime Interop because it also involves System Text Json

// MVC - Web API
builder.Services.AddControllers()
            .AddJsonOptions(options => ... );
// Minimal API
builder.Services.Configure<JsonOptions>(options =>
{
     ...
});
LinQiaoPorco commented 1 month ago

I found my data need persist have a object cycle issue, try to fix it with another JsonSerealizeOption. But there is no way to add it in PersistAsJson<TValue>(String, TValue).