[Repo Assist] perf: HtmlNode.serialize avoids per-indent string alloc; isVoidElement as module-level constant#1768
Open
github-actions[bot] wants to merge 5 commits intomainfrom
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>
Contributor
Author
|
Commit pushed:
|
13 tasks
…29-3c3cf8d8a964a909
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.
🤖 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.