Repository navigation
[release/11.0] [blazor] Avoid quadratic MarkupString insertion - #70904
Open
github-actions[bot] wants to merge 1 commit into
Open
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
* [blazor] Avoid quadratic MarkupString insertion Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * [blazor] Replace mutation observer with linear cleanup Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
|
Hi @github-actions[bot]. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge. To learn more about how to prepare a servicing PR click here. |
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.
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
f6270f0cd7640a8c8b3de3a0519f159388fd0c15↑ On main: 54 JS tests and 9 focused Selenium tests passed after merging latest main.
↓ Not built or tested on release/11.0; CI for this PR not yet inspected.
↓ Ownership of script-moved markup nodes changes and is not covered by permanent tests.
↑ release/11.0 contains the #66007 orphan sweep that causes the scan.
↓ Benchmarked in an in-tree sample, not the reporter's 1.3 MB Markdig document or a .NET 10 comparison.
Backport of #70533 to release/11.0
/cc @maraf
[blazor] Avoid quadratic MarkupString insertion
Make rendering a
MarkupStringwith many top-level nodes linear again.Description
#66007 added a sweep to
insertLogicalChildthat scans every logical sibling of the parent for orphaned nodes on each insertion.insertMarkupinserts each top-level node of aMarkupStringinto the same new container, so a fragment with n top-level nodes did about n²/2 sibling checks.Because the markup container is newly created, its nodes can be appended without scanning earlier siblings: every insertion was already an append, so DOM output and script execution order are unchanged. After all nodes are inserted, a single linear pass drops nodes that scripts or custom elements disconnected during insertion. All other logical insertions keep the #66007 orphan handling, including creation of the markup container itself.
Behavior notes, affecting only scripts or custom elements that externally mutate Blazor-rendered markup:
<script>) is now dropped from tracking, so the next update of that markup no longer throwsCannot read properties of null (reading 'removeChild').Fixes #70503
Customer Impact
Apps that render large HTML through
MarkupString(for example, Markdown converted to HTML) can freeze the page. The issue reports an 18,000-paragraph document confirming in 8,700 ms on 11.0.0 versus 47 ms on .NET 10 (18.75 s under CPU load). Blazor Server, WebAssembly, and Blazor Hybrid (BlazorWebViewin MAUI, WPF, and WinForms) share the affected script. The only workaround is to wrap the markup in a single root element.Regression?
Regressed from .NET 10 by #66007, which shipped in 11.0.0.
Risk
The change is limited to
insertMarkupand a new linear helper inLogicalElements.ts;insertLogicalChildscans by default, so other callers and the enhanced-navigation fix from #66007 are unchanged. Visible output and script order are unchanged. The only behavior differences involve scripts externally mutating Blazor-managed DOM, which Blazor documents as unsupported.Verification
Verified on
mainbefore merge; this backport is identical and was not separately built or tested onrelease/11.0.parentNodereads.removeChilderror above.main: 54 focused JavaScript tests and 9 focused Selenium tests passed, including the Fix Blazor crash when interactive component is in layout with enhanced nav #66007 enhanced-navigation regression test.Packaging changes reviewed?
When servicing release/2.3
Note
This PR description was generated with the assistance of GitHub Copilot.