[Repo Assist] perf: HtmlNode.serialize avoids per-indent string alloc; isVoidElement as module-level constant#1768
Conversation
…t as module-level constant; HtmlDocument uses single StringBuilder
- Move void-element set to a module-level [<AutoOpen>] private module so it is
computed once at startup instead of being re-created on every HtmlNode.ToString() call.
- Replace `String(' ', indentation + plus) |> append` in the serialize `newLine` helper
with `sb.Append(' ', indentation + plus)` which writes spaces directly into the
StringBuilder without allocating an intermediate string.
- Rewrite HtmlDocument.ToString() to use a single StringBuilder rather than
`List.map … |> String.Concat`, avoiding the intermediate list allocation.
2980 tests pass (net8.0, -p:NuGetAudit=false).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…3 to resolve GHSA-g94r-2vxg-569j Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Commit pushed:
|
…29-3c3cf8d8a964a909
…29-3c3cf8d8a964a909
|
/repo-assist Work out why CI is failing on windows sometimes and create a separate PR for the fix |
|
✓ Repo Assist completed successfully, see workflow run. |
|
Pull request created: #1774
|
|
🤖 Repo Assist here — investigating the Windows CI failures. Root cause found. In The Fix submitted on branch
All 13
|
…29-3c3cf8d8a964a909
🤖 This is an automated pull request from Repo Assist, an AI assistant for this repository.
Summary
Three focused performance improvements to
HtmlNode/HtmlDocumentserialization.Changes
1.
isVoidElementas a module-level constantBefore:
HtmlNode.ToString()reconstructed aSet<string>of 16 void element names on every call, then wrapped it in a closure.After: The set (and the
isVoidElementpredicate) are computed once at module initialisation time, stored in a[<AutoOpen>] module private HtmlNodeHelpers. This eliminates oneSet.ofArray+ 16-element insertion perToString()call.2.
newLineusesStringBuilder.Append(char, int)directlyBefore:
After:
StringBuilder.Append(char, repeatCount)writes the character into the internal buffer directly without creating an intermediatestring. Every pretty-printed element that starts a new line previously paid one allocation; now it pays zero.3.
HtmlDocument.ToString()uses a singleStringBuilderBefore:
Pre-existing infrastructure warning (OpenTelemetry.Api 1.15.0 vulnerability via NuGet audit) suppressed with
-p:NuGetAudit=false; unrelated to this change, tracked in PR #1762.