From a8df5e3df9b8cc9c1c42acf2858ce748e9983813 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Sat, 12 Sep 2026 17:44:14 +1200 Subject: [PATCH] Compile the element style pattern once instead of once per primitive setPainterStyle() built its QRegularExpression as a local, so the pattern was compiled from scratch on every call -- and it is called for every graphics primitive of every element instance a project places. A callgrind profile of opening examples/affuteuse_250h.qet put 28 % of all instructions inside libpcre2, and 12 % of the whole run inside this one function. Making it static const compiles the pattern once for the life of the process. Nothing else changes: same pattern, same matching, same named captures. Measured with callgrind, which counts instructions and so does not depend on what else the machine is doing, opening examples/affuteuse_250h.qet: 4,801,381,735 -> 4,297,629,948 instructions (-10.5 %) setPainterStyle 582 M (12.13 %) -> 79 M (1.83 %) --info stays byte identical on all 23 example projects, and so does every SVG this produces for industrial.qet -- which is the output that would change if the styles were parsed any differently. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01N64mk33R9GdbU1PkYcc9SP --- sources/factory/elementpicturefactory.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sources/factory/elementpicturefactory.cpp b/sources/factory/elementpicturefactory.cpp index cf0d89bf6..1b256aff9 100644 --- a/sources/factory/elementpicturefactory.cpp +++ b/sources/factory/elementpicturefactory.cpp @@ -621,7 +621,11 @@ void ElementPictureFactory::setPainterStyle(const QDomElement &dom, QPainter &pa //Get the couples style/value const QStringList styles = dom.attribute("style").split(";", Qt::SkipEmptyParts); - QRegularExpression rx("^(?[a-z-]+):(?[a-zA-Z-]+)$"); + //Built once : this runs for every primitive of every element + //instance a project places, and recompiling the pattern each time + //was the single largest cost of opening a project. + static const QRegularExpression rx( + QStringLiteral("^(?[a-z-]+):(?[a-zA-Z-]+)$")); if (!rx.isValid()) { qWarning() <