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.41k stars 10k forks source link

[Question] Get the reason wich cause a component re-render - too many OnAfterRender #14684

Closed julienGrd closed 5 years ago

julienGrd commented 5 years ago

Hi guys, i faced actually a big performance issue with my app built in blazor.

I precise my app can run in server and client mode and the performance issue is only in client mode (web assembly)

I have a view with a component which containing a large table with grouping functionnalty things like that.

I have some action outside this component which can recharge the grid.

On some actions, i freeze the app during 40 seconds, so i put some console.Writeline to see what's happen

I will not put all details of the logs but the things is it seem my component is rendered 9 times, on interval of 3 or 4 seconds approximatively (so i retrieve my 40 seconds off freeze).

One is justified, is when my component itself recharge when he see data changed (i put a log inside this place too, it called only one time).

I put a log in the OnParameterSet => this event is not called and its logic

I centralise all my StateHasChanged of all my components in a central method. These method is called only one time, on the handler when my data changed. On this place it seem Ok too.

So i have finally 8 OnAfterRender completely mysterious and it's huge problem for me to not understand from where they come from.

Unfortunately i can't reproduce the problem, my app is really big and complex, she use external code (existing silverlight ViewModel) and external services (existing Wcf services), so i have to debug by myself, that's why i need information.

So if you have idea on how i can "retrieve" the origin of theses render let me know !

Thanks for your help !

Julien

mkArtakMSFT commented 5 years ago

Thanks for contacting us, @julienGrd. You can try to override the protected bool void ShouldRender() method and add a breakpoint in there. And then look into the call-stack to understand where from it's being called.

julienGrd commented 5 years ago

@mkArtakMSFT yes it help me a lot thank you ! I find the guilty, it seem provide from this extension : https://github.com/mikoskinen/Blazor.EventAggregator/. Each publish seem re-render all the components wich suscribe (event with different class parameter).