Description
In .NET 5, RenderTreeFrame
stopped being readonly
in order to support some performance optimizations focused on WebAssembly. Generally this did not have any drawbacks because:
- The mutability is
internal
. We didn't make it publicly mutable. - The framework always passes around
RenderTreeFrame
either withref
or with no modifier - Or in the case of
RenderTreeDiffBuilder.NextSiblingIndex
, it does usein
but it doesn't make any method calls or property accesses inside it (we probably should change this to useref
to have the behavior be more obvious).
However there remains one other case: RenderBatchWriter
's Write
method:
void Write(in RenderTreeFrame frame)
{
....
}
Inside there, it performs lots of property reads. If this blog post about perf implications of in
is correct, that means there will be lots of defensive copies happening.
To fix this, we could either remove the in
modifier and just have a single copy made for each call to Write
, or we could replace in
with ref
and have no copies made.
I don't yet have any specific measurement of the perf effects. We should at least try to measure this before committing to a specific resolution. It might not really have any observable real-world effects because RenderBatchWriter
is so fast anyway relative to other things that are going on, such as transmitting render batches over the network.