[Blazor] Better diagnostics for Blazor server #43513
Labels
area-blazor
Includes: Blazor, Razor Components
enhancement
This issue represents an ask for new feature or an enhancement to an existing one
feature-blazor-server
Pillar: Dev Experience
Milestone
We get a lot of questions/issues opened about Blazor Server memory management. It is clear that this is a confusing aspect for customers and that they run into issues when they inadvertently introduce problematic patterns in their apps, like components rendering a large set of elements which can cause the memory to grow significantly.
When a customer finds itself in this situation, they generally open an issue with us that suggest there is a memory leak in the framework (which has not been the case so far) and we get into a discussion where we explain how Blazor deals with circuits, how memory works in Server GC and how to troubleshoot memory issues. The general points that people miss are:
It will be extremely helpful if we can add additional diagnostics to help bring visibility into some of the internal aspects of how Blazor server operates. Specifically:
This makes it trivial to prove that we are handling the circuit lifetime correctly (or to spot when we are not) and since all the allocated framework memory is rooted by a circuit, it makes it easy to prove that the memory issue is not on the framework.
Further diagnostics to help identify problematic circuit instances using clrMD to identify circuits consuming a large amount of memory. We can do this as follows:
_itemsInUse
._itemsInUse
will be large._items
will be large.With this data, we should be able to point out what components rendered a large number of elements currently or in the past as well as what circuit they belong(ed) to and its current state (whether the circuit is active, disconnected, or waiting to be collected) and it should also help discard the framework or the component rendering as the source of the memory issues.
Note that this could also be extended to use something similar to
!objsize
on a component instance to track how much memory that component is allocating, which in turn would help identify components in the app that are holding on to a lot of memory (think for example a component that has a large list in memory).This last bit is not only useful for Blazor Server but it might be useful too for Blazor Webassembly and Desktop.
Another way to identify issues with the app this issue would be to check the
ArrayPool<RenderTreeFrame>
to identify large buffers that might have been allocated by the app in the past.Examples of issues in this area in the past (there are likely more):
#43221
#39238
#39156
#33547
#33077
#32588
#30210
#21991
#18556
#17945
#14545
#10623
The text was updated successfully, but these errors were encountered: