[New-bugs-announce] [issue24424] xml.dom.minidom: performance issue with Node.insertBefore()

Robert Haschke report at bugs.python.org
Wed Jun 10 15:29:16 CEST 2015

New submission from Robert Haschke:

Node.insertBefore() has a serious performance issue:

Using self.childNodes.index(refChild) it searches for the correct index in childNodes where the newChild should be inserted.
However, index() is linear in time w.r.t. the size of childNodes.
Hence, if there are many children, runtime dramatically increases.

Adding a simple caching mechanism (caching the previously used reference)
I was able to reduce runtime in my particular case from 16s to 1.6s, i.e. a factor of 10!

components: XML
files: minidom.insertBefore.patch
keywords: patch
messages: 245128
nosy: Robert Haschke
priority: normal
severity: normal
status: open
title: xml.dom.minidom: performance issue with Node.insertBefore()
type: performance
versions: Python 2.7
Added file: http://bugs.python.org/file39674/minidom.insertBefore.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list