Skip to content
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

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

Open
1 task done
ysmoradi opened this issue Mar 13, 2022 · 6 comments
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-prerendering Issues related to prerendering blazor components Pillar: Technical Debt Priority:1 Work that is critical for the release, but we could probably ship without

Comments

@ysmoradi
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

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

@javiercn javiercn added area-blazor Includes: Blazor, Razor Components feature-prerendering Issues related to prerendering blazor components labels Mar 14, 2022
@mkArtakMSFT mkArtakMSFT added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Mar 14, 2022
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Mar 14, 2022
@ghost
Copy link

ghost commented Mar 14, 2022

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
Copy link
Author

ysmoradi commented Aug 9, 2023

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
Copy link

ghost commented Jan 3, 2024

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
Copy link
Member

Related #31877

@ysmoradi
Copy link
Author

ysmoradi commented Jan 3, 2024

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 =>
{
     ...
});

@mkArtakMSFT mkArtakMSFT added Priority:1 Work that is critical for the release, but we could probably ship without and removed Perf labels Jan 3, 2024
@LinQiaoPorco
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-prerendering Issues related to prerendering blazor components Pillar: Technical Debt Priority:1 Work that is critical for the release, but we could probably ship without
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants