Skip to content

Using bind causes massive traffic in server side blazor #10558

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

Closed
jsandv opened this issue May 27, 2019 · 11 comments
Closed

Using bind causes massive traffic in server side blazor #10558

jsandv opened this issue May 27, 2019 · 11 comments
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-blazor-server feature-rendering Features dealing with how blazor renders components ✔️ Resolution: Duplicate Resolved as a duplicate of another issue investigate Perf severity-major This label is used by an internal tool Status: Resolved
Milestone

Comments

@jsandv
Copy link

jsandv commented May 27, 2019

Im working on a small simple drawing tool in server side blazor using the latest template in VS2019 .net core 3-preview. When I was stress testing my app, adding 500 elements it became extremely unresponsive.
When inspecting the websocket connection i saw lots of packages over 35kb while moving the mouse. This does not make sense to me, because im not changing anything.
Anyways after some experiments I have located something suspecious causing this.
Using bind on an element like this:
1)<input type ="text" bind="@Text"/>
is completely diffrent then this:
2)<input type ="text" value="@Text" onchange="@(e=>e.Value)"/>

The first one is resending entire page over websocket each mouse move (which seems to be at least 10 times per second)
The second one is resending entire page over websocket only when I change the text.

1)This one using bind sends 35kb packages

@page "/"
<div onmousemove="@(e=>MouseMove(e))">
    @for(var i = 0; i < 1000; i++)
    {
        <input type ="text" bind="@Text"/>
    }
</div>

@functions{
    public string Text { get; set; }
    public void MouseMove(UIMouseEventArgs e)
    {

    }
}

This one works as expected with regards to data sent over websocket

@page "/"
<div onmousemove="@(e=>MouseMove(e))">
    @for(var i = 0; i < 1000; i++)
    {
        <input type ="text" value="@Text" onchange="@(e=>OnTextChange(e))"/>
    }
</div>

@functions{
    public string Text { get; set; }
    public void MouseMove(UIMouseEventArgs e)
    {

    }
    public void OnTextChange(UIChangeEventArgs e)
    {
        Text = e.Value.ToString();
    }
}

image

@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label May 28, 2019
@SteveSandersonMS
Copy link
Member

FYI what is changing on every mouse move is the event handlers. You’re disposing 1000 handlers and assigning 1000 new ones on each mouse move. This is because the framework can’t detect that the new handlers are functionally equivalent to the old ones.

@mkArtakMSFT
Copy link
Contributor

To add to what @SteveSandersonMS has mentioned here, we're going to introduce a mechanism for reducing the impact of these type of aggressive events on the server as part of #10522

@mkArtakMSFT
Copy link
Contributor

@SteveSandersonMS is there anything else we plan to do here?

@Andrzej-W
Copy link

I'm not the author of original question, but after reading the answer from @SteveSandersonMS I have to say that I don't know which event handlers are disposed and assigned again. Please note that according to the author second example with onchange handler works as expected. First one without explicit event handlers sends to much data. I agree that it is not expected.

@mkArtakMSFT I agree that we need event throttling but the problem described above is different.

@mkArtakMSFT
Copy link
Contributor

/ping @SteveSandersonMS

@mkArtakMSFT mkArtakMSFT added this to the 3.1.0 milestone Jun 10, 2019
@SteveSandersonMS
Copy link
Member

Not certain what I'm being pinged for. This is scheduled to be investigated for 3.1, right?

@mkArtakMSFT mkArtakMSFT modified the milestones: 3.1.0, Backlog Aug 5, 2019
@mkArtakMSFT
Copy link
Contributor

We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

@ChristianWeyer
Copy link

@jsandv Are you still seeing this behavior with latest bits?

@jsandv
Copy link
Author

jsandv commented Apr 22, 2020

@ChristianWeyer yes im seeing this in latest bits.

Current steps to reproduce is having either section 1 or section 2 commented in.
Run in any valid page.

`

@page "/counter"
Section 2: Not optimal, entire page is sent each mouse move
<div @onmousemove="e=>MouseMove(e)">
    @for (var i = 0; i < 1000; i++)
    {
        <input type="text" @bind="Text" />
    }
</div>

@*Section 2: Optimal, only few bytes transferred each mouse move
<div @onmousemove="e=>MouseMove(e)">
    @for (var i = 0; i < 1000; i++)
    {
        <input type="text" value="@Text" @onchange="e=>OnTextChange(e)" />
    }
</div>*@

@code {
    public string Text { get; set; } = "s";
    public void MouseMove(MouseEventArgs e)
    {

    }
    public void OnTextChange(ChangeEventArgs e)
    {
        Text = e.Value.ToString();
    }
}

`

@endeffects
Copy link

I have the same issue with a diagram component i'm working on.
How more shapes i'm adding to it how more traffic is generated
by dragging and dropping a single element.

The structure of my page is similar to the sample above,
i have an outer svg to handle the drag and drop events:

<svg @onmousemove="this.OnMouseMove" @onmouseup="this.OnMouseUp" />

And multiple child rectangles where i'm capturing the selection events:

<g @onmousedown="this.OnItemSelected"> .. </g>

So my question is, does it make more sense to move all child event bindings
to the parent svg to improve the performance? Or is blazor able to handle this
and i missed something in my implementation?

@SteveSandersonMS SteveSandersonMS added affected-few This issue impacts only small number of customers bug This issue describes a behavior which is not expected - a bug. severity-major This label is used by an internal tool labels Oct 9, 2020 — with ASP.NET Core Issue Ranking
@SteveSandersonMS SteveSandersonMS removed their assignment Nov 23, 2020
@javiercn javiercn added feature-blazor-server feature-rendering Features dealing with how blazor renders components labels Apr 19, 2021
@TanayParikh
Copy link
Contributor

Closing as dup of #10522.

@TanayParikh TanayParikh added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Oct 19, 2021
@ghost ghost added the Status: Resolved label Oct 19, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-few This issue impacts only small number of customers area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-blazor-server feature-rendering Features dealing with how blazor renders components ✔️ Resolution: Duplicate Resolved as a duplicate of another issue investigate Perf severity-major This label is used by an internal tool Status: Resolved
Projects
None yet
Development

No branches or pull requests

8 participants