-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Use view buffers during pre-rendering #39465
Conversation
2bd50ea
to
68d847e
Compare
Server, | ||
WebAssembly, | ||
ServerAndWebAssembly | ||
var viewBuffer = new ViewBuffer(_viewBufferScope, nameof(ComponentRenderer), 16); // Preamble is fixed size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we later change the preamble size, and don't realise we should also update this line, will we cause adverse perf effects? Is there any way to make it fail if we do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the instantiation of the viewbuffer should be done inside WebAssemblyComponentSerializer.AppendPreamble
so it's all localized to one bit of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks good to me, even though the concept of MVC view buffers is new to me and so it's possible I might be missing some subtlety. I'm approving based on what I know, but would recommend getting confirmation from @javiercn too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SteveSandersonMS ViewBuffers are an MVC abstraction for ArrayPool<T>
that are rented for the duration of view rendering. The view rendering system has some optimizations that makes it efficient to use these when rendering because we know it's safe to transfer ownership of the underlying arrays around since the rented lifetime is well understood:
f8ce8ac
to
70deb39
Compare
* Use view buffers during rendering This change removes about 8kb of string[] allocations per request during pre-rendering and replaces them with a ViewBuffer that uses array pooling. The allocations come from list resizing as part of HtmlRenderer operations (such as https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/HtmlRenderer.cs#L133-L134). Also includes a couple of other clean up items: * Uses ValueTask instead of `Task<T>` * Moves top-level types to a separate file. * Some formatting cleanup
This change removes about 8kb of string[] allocations per request during pre-rendering and replaces them with a ViewBuffer that uses array pooling. The allocations come from list resizing as part of HtmlRenderer operations (such as https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.ViewFeatures/src/RazorComponents/HtmlRenderer.cs#L133-L134). Also includes a couple of other clean up items:
Task<T>
Details: https://github.com/dotnet/aspnetcore-internal/issues/3983