From de82b2738f3ca877921a4bbdcf730eb96dd5bc9f Mon Sep 17 00:00:00 2001 From: Dieter Mayer Date: Tue, 28 Jul 2026 14:07:51 +0200 Subject: [PATCH] XmlElementCollection::child(): linear sibling walk instead of item(i) The child lookup iterated parent_element.childNodes() via item(i), and QDomNodeList::item() walks the sibling chain from the start on every call - making the loop quadratic in the number of children, with an extra QList allocation and a second pass on top. This lookup runs several times per element instance while loading a project, against the "import" category that holds every embedded definition, so the cost scales with (instances x embedded definitions). Replace it with a firstChildElement()/nextSiblingElement() walk with an early return. Same semantics (first tag+name match in document order). Measured on the Kaefer_1303 reference project (3.9 MB, 23 folios, 432 instances, media of 6 runs, Windows/MinGW, same GCC for both): before after Qt5 5.116 s 5.068 s Qt6 6.683 s 4.640 s (-31 %) This removes the entire Qt6 load-time regression discussed in #553 - Qt6 goes from +31 % slower to 8 % faster than Qt5 on the very project that exposed it (Qt6''s QDom makes the quadratic pattern much more expensive than Qt5''s did). Smaller projects gain too (3.4 MB example: -9 % on Qt6). (cherry picked from commit 0d4ef8eca27601c37ba2b75d7c058e9d8e2beea4) --- .../xmlelementcollection.cpp | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/sources/ElementsCollection/xmlelementcollection.cpp b/sources/ElementsCollection/xmlelementcollection.cpp index d6e3319bf..b124b72ff 100644 --- a/sources/ElementsCollection/xmlelementcollection.cpp +++ b/sources/ElementsCollection/xmlelementcollection.cpp @@ -186,23 +186,22 @@ QDomElement XmlElementCollection::child(const QDomElement &parent_element, if (parent_element.ownerDocument() != m_dom_document) return QDomElement(); - //Get all childs element of parent_element - QDomNodeList child_list = parent_element.childNodes(); - QString tag_name(child_name.endsWith(".elmt")? "element" : "category"); - QList found_dom_element; - for (int i=0 ; i