Skip to content

Inserting a MarkupString with many top-level nodes is quadratic since .NET 11 (insertLogicalChild orphan scan) #70503

Description

@Daeer-Projects

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Since .NET 11, inserting a MarkupString with many top-level nodes is quadratic in the number of nodes.

insertLogicalChild in src/Components/Web.JS/src/Rendering/LogicalElements.ts gained an orphan-removal loop in #66007 ("Fix Blazor crash when interactive component is in layout with enhanced nav"). The loop walks the whole logical-children array of the parent on every call:

const newSiblings = getLogicalChildrenArray(parent);
for (let i = newSiblings.length - 1; i >= 0; i--) {
  const sibling = newSiblings[i] as any as Node;
  if (!sibling.parentNode) { ... }
}

BrowserRenderer.insertMarkup calls insertLogicalChild once per top-level node of the parsed markup, into the same container, so inserting markup with n top-level nodes does about n²/2 sibling checks.

Expected Behavior

Inserting a large MarkupString costs about the same as on .NET 10.

Steps To Reproduce

Render a MarkupString holding many top-level elements, for example the HTML Markdig produces for a 1.2 MB Markdown document of short paragraphs (about 18,000 <p> elements, 1.3 MB of HTML), in a Blazor Server component.

Measured with the server's own RemoteRenderer log (Completing batch N without error in X ms, which runs when the browser confirms the batch), same machine, same 1,309,606-byte render batch, nothing else running:

Runtime Batch confirmed after
.NET 10 (ASP.NET Core 10.0.x) 47 ms
.NET 11 (ASP.NET Core 11.0.0) 8,700 ms
.NET 11, same HTML inside one <div> (one top-level node) 23 ms

Under CPU load the .NET 11 case took 18.75 s.

Workaround

Wrap the markup in a single root element, so insertMarkup inserts one node and the browser's parser builds the rest.

Possible fix

Do the orphan sweep once per insertMarkup (or per render batch) rather than inside each insertLogicalChild, or only when the computed nextSibling is actually disconnected.

.NET Version

11.0.100

Anything else?

The same script is used by Blazor Hybrid (BlazorWebView), so MAUI and WPF/WinForms hosts are affected as well.

Activity

  1. added
    area-blazor
    on Nov 11, 2026
  2. github-actions commented on Nov 11, 2026

    @github-actions
    Contributor

    Triage Summary

    Area: area-blazor (insertLogicalChild in src/Components/Web.JS/src/Rendering/LogicalElements.ts, BrowserRenderer.insertMarkup)
    Type: Bug (insertion of a MarkupString with many top-level nodes is slower on .NET 11 than on .NET 10)

    Regression Info

    • Previously working version: ASP.NET Core 10.0.x (batch confirmed after 47 ms, per reporter)
    • Failing version: ASP.NET Core 11.0.0 (batch confirmed after 8,700 ms, per reporter)
    • Same 1,309,606-byte render batch on the same machine; wrapping the markup in a single root element takes 23 ms on .NET 11 (reporter-supplied measurements).

    Potential Duplicates

    • None found

    Generated by Issue Triage Agent for dotnet/aspnetcore for #70503 · copilot · auto · 22.6 AIC · ⌖ 1.02 AIC · ⊞ 7.5K · ◷

  3. added this to the 11.0.x milestone on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Regressionarea-blazorperformance

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions