Skip to content

Optimize RenderBatchWriter for empty diffs #45831

@petr-horny-bsshop

Description

@petr-horny-bsshop

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.

If we have a component that creates an empty diff when re-rendering, i.e. there was no change in the resulting markup, this empty diff is still sent to the server and takes up a certain size in the serialized data.

For example, consider this component:

@Value.DayOfWeek

@code {

    [Parameter]
    public DateTime Value { get; set; }
}

Render the above component 1000 times:

@page "/"
<button @onclick="@(StateHasChanged)">Render</button>
<br />

@for (var i = 0; i < 1000; i++)
{
    <Component Value="DateTime.Now" />
}

Click the "Render" button.

Despite the fact that the resulting markup does not change (it changes once every 24 hours), 12 kB of data is sent to the server:

2023-01-02 14_51_54-PlayGround (Debugging) - Microsoft Visual Studio

2023-01-02 14_52_27-+  0  = {Microsoft AspNetCore Components RenderTree RenderTreeDiff}

It can be seen that the data sent is very "sparse":

2023-01-02 14_49_34-BlazorServerApp1

This particular case could of course be optimized using the ShouldRender method. However, in general it doesn't make sense (at least I think so) to send an empty diff to the client.

Describe the solution you'd like

Modify the int Write(in ArrayRange<RenderTreeDiff> diffs) method in RenderBatchWriter to ignore empty diffs.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-renderingFeatures dealing with how blazor renders components

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions