-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Control when StateHasChanged has finished #11760
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
Comments
I see. Yes, that would be convenient in some cases. The drawback is that then the framework would have to do some extra internal tracking, so it could remember all the callbacks and their associations with different rendering requests. We'd need some new internal data structures which would involve extra heap allocations during the render cycle. Since this is an unusual case and handling it comes with real perf drawbacks, I think it's not something we'd be likely to do in the foreseeable future. Generally there are a couple of more practical ways to deal with initialization of descendants:
If these approaches aren't viable in your case, it would be great to know more about what you're doing. Hope that makes sense! |
Thanks @SteveSandersonMS, the suggested approaches are viable. The idea was about providing an additional convenient way of handling the same, but as this comes at a cost, then Out of curiosity:
are there any ideas for a general improvement that will probably make the extra heap allocations not that critical according to performance? I suppose that this is very important for the wasm hosting model. |
GC is always a major consideration for perf on .NET. We've done a lot of work in ASP.NET Core generally, and Blazor specifically, to minimize GC costs, and I expect that to continue indefinitely. Our goal is to make the framework as GC-light as possible so that application developers have more headroom to do what they want that might stress the GC more. There's probably no magic bullet to fix this, however in the long run GC might get a lot cheaper if WebAssembly itself can provide a managed heap, which is one of the proposals being worked on by the WebAssembly specs group. |
Is your feature request related to a problem? Please describe.
In blazor, in scenarios like dynamically initializing components, it will be handy to have an option to pass a "callback" to
StateHasChanged
instead of putting the logic in a life-cycle method likeOnAfterRender
. This is somewhat more convenient and easy to read.For example:
can be written like:
Another option might be to await it, but this implies a new method, e.g.
StateHasChangedAsync
:Currently, I am not able to implement this approach as wrapping the call in a Task.Run():
fails with an exception:
Still, having a callback seems more convenient and it also doesn't introduce a new method.
The text was updated successfully, but these errors were encountered: