From 139c47d1ce9f1c1b6d8f85ed8bc1a536be2bf8cb Mon Sep 17 00:00:00 2001 From: Dieter Mayer Date: Mon, 27 Jul 2026 11:59:11 +0200 Subject: [PATCH] ElementFactory: read link_type from the cached QDom, drop pugixml pass createElement() ran a full pugixml parse of the element definition for every instance, only to read the link_type attribute for the subclass dispatch - on a big example project (191 instances) 49 ms of the load, measured with temporary instrumentation. The QDom definition is already cached and the ctor uses it anyway; reading the attribute there costs ~17 ms in total, so the net win is ~30 ms - within run-to-run noise end-to-end, but it removes an entire redundant parser pass per element. Behavior unchanged: an absent and an empty link_type both fell through to SimpleElement before and still do. (cherry picked from commit d63275971f558c8ac59f35bf4d13d7e424682342) --- sources/factory/elementfactory.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sources/factory/elementfactory.cpp b/sources/factory/elementfactory.cpp index ed22d3896..883b30804 100644 --- a/sources/factory/elementfactory.cpp +++ b/sources/factory/elementfactory.cpp @@ -42,10 +42,14 @@ Element * ElementFactory::createElement(const ElementsLocation &location, QGraph return nullptr; } - auto doc = location.pugiXml(); - if (doc.document_element().attribute("link_type")) + //Read the link_type from the (cached) QDom definition instead of + //running a second, pugixml parse of the same definition: this + //dispatch runs once per element instance on project load, and the + //pugixml detour was ~4 % of the whole load time of a big project. + const QString link_type = + location.xml().attribute(QStringLiteral("link_type")); + if (!link_type.isEmpty()) { - QString link_type(doc.document_element().attribute("link_type").as_string()); if (link_type == QLatin1String("next_report") || link_type == QLatin1String("previous_report")) return (new ReportElement(location, link_type, qgi, state)); if (link_type == QLatin1String("master")) @@ -55,7 +59,7 @@ Element * ElementFactory::createElement(const ElementsLocation &location, QGraph if (link_type == QLatin1String("terminal")) return (new TerminalElement (location, qgi, state)); } - + //default if nothing match for link_type return (new SimpleElement(location, qgi, state)); }