Skip to content

Blazor Server RenderBatchWriter should stop defensive copies of RenderTreeFrame on Write method #25764

Open
@SteveSandersonMS

Description

@SteveSandersonMS

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 with ref or with no modifier
  • Or in the case of RenderTreeDiffBuilder.NextSiblingIndex, it does use in but it doesn't make any method calls or property accesses inside it (we probably should change this to use ref 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    PerfPillar: Technical DebtPriority:2Work that is important, but not critical for the releaseaffected-allThis issue impacts all the customersarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-renderingFeatures dealing with how blazor renders componentsseverity-nice-to-haveThis label is used by an internal tool

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions