GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — xml.dom.minidom: Node.normalize() is quadratic in the number of adjacent text nodes · Issue #158860 · python/cpython

xml.dom.minidom: Node.normalize() is quadratic in the number of adjacent text nodes #158860

New issue
Copy link
New issue
Copy link
Open
Open
xml.dom.minidom: Node.normalize() is quadratic in the number of adjacent text nodes#158860
Copy link
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-XMLtype-featureA feature request or enhancementA feature request or enhancement

Description

@jonbaldie
jonbaldie
opened on Oct 5, 2026
Issue body actions

xml.dom.minidom.Node.normalize() merges adjacent text nodes with node.data = node.data + child.data, once per absorbed node. A run of n text nodes copies the growing string n times, so it's quadratic.

from xml.dom.minidom import Document
doc = Document()
root = doc.appendChild(doc.createElement('r'))
for _ in range(32_000):
    root.appendChild(doc.createTextNode('x' * 48))
root.normalize()  # ~450 ms; 8k nodes ~25 ms, 16k ~95 ms

The parsers already merge character data, so you only hit this with documents built through the DOM API (appendChild/createTextNode, etc.).

Fix: collect the pieces for each run and ''.join them once at the end. I'll open a PR.

Linked PRs

  • gh-158860: Make minidom Node.normalize() linear in adjacent text nodes #158861

Activity

  1. aisk
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    topic-XML
    type-featureA feature request or enhancementA feature request or enhancement
    performancePerformance or resource usagePerformance or resource usage
    on Oct 5, 2026
  2. kevinprimeraquecreo-stack
    added this to Project_VKon Oct 18, 2026
  3. github-project-automation
    moved this to Todo in Project_VKon Oct 18, 2026
  4. kevinprimeraquecreo-stack
    added this to Project_VKon Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-XMLtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.