Repository navigation
Conversation
RenderElement compared every element name case-insensitively against textarea, form, option, select and script, and looked it up in a HashSet of self-closing elements. Replace those with a single length-based dispatch that returns an ElementKind, and merge a few adjacent literal writes. Adds HtmlRendererBenchmark. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The required frozen review bundle and existing-feedback snapshot are missing, preventing verification of revision provenance and feedback deduplication.
No open issues 🎉
What changed in this PR
Optimizes static HTML rendering by classifying element names once, preserving existing case-insensitive handling and HTML output.
Changes:
- Replaces repeated element-name checks and the self-closing-element lookup with a length-based classifier.
- Combines adjacent literal writes for attributes and form actions.
- Adds benchmarks for HTML writing alone and rendering plus writing, with the required Components.Web project reference.
| File | Description |
|---|---|
src/Components/Web/src/HtmlRendering/StaticHtmlRenderer.HtmlWriting.cs |
Adds element classification and combines literal writes. |
src/Components/Components/perf/Microsoft.AspNetCore.Components.Performance.csproj |
References Components.Web for renderer benchmarks. |
src/Components/Components/perf/HtmlRendererBenchmark.cs |
Adds two benchmarks using a 100-row component table. |
Review effort: Balanced
Member
Author
|
Compliance check: no public API changes ( 🤖 Posted by ASP.NET Core Perf 2 (AI Agent) |
Member
|
/review |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
StaticHtmlRenderer.RenderElementdid several case-insensitive comparisons for every element it wrote:textarea,form,option,selectandscriptwere each checked withstring.Equals(..., OrdinalIgnoreCase);HashSet<string>(OrdinalIgnoreCase)of self-closing elements, which hashes the name case-insensitively.Description
switchinto a smallElementKindenum. The comparisons are stillOrdinalIgnoreCase, but most names are rejected by length alone.SelfClosingElementsHashSet. The same 14 elements are matched in the switch.frame.ElementNameinto a local, and merge adjacent literal writes:'='+'"'becomes"=\"", and' '+"action"+'='+'"'becomes" action=\"".The output is unchanged.
Benchmarks
I added
HtmlRendererBenchmarkinsrc/Components/Components/perf. It renders a 100-row table whose rows are child components, each with attributes, a checkbox and a link. The perf project now referencesMicrosoft.AspNetCore.Components.Web.Local BenchmarkDotNet, InProcess, 3 interleaved rounds against main:
WriteHtmlOnly(HTML writing only, to aStringWriter)RenderAndWriteHtml(new renderer, render, then write)Allocations are unchanged: 128 B and 144,760 B.
Tests
Microsoft.AspNetCore.Components.Web.Tests: 330 passed, which includes the HtmlRenderer tests covering self-closing elements, textarea, select/option, form action and script.Microsoft.AspNetCore.Components.Endpoints.Tests: 883 passed.🤖 Posted by ASP.NET Core Perf 2 (AI Agent)