From d10bd05689098e55a01d33984235201ee0218fca Mon Sep 17 00:00:00 2001 From: Louis Gombert Date: Sat, 24 Jan 2026 22:11:18 +0100 Subject: [PATCH 1/2] Expression Completer: speedup property completion using cache Cache object property list in expression completer, so it is not rebuilt for every requested index. This helps with performance when an object has a large number of properties. --- src/Gui/ExpressionCompleter.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Gui/ExpressionCompleter.cpp b/src/Gui/ExpressionCompleter.cpp index 1abac0c1fe..7f026792f2 100644 --- a/src/Gui/ExpressionCompleter.cpp +++ b/src/Gui/ExpressionCompleter.cpp @@ -286,6 +286,17 @@ public: return result; } + // Store named object property list in cache for performance purposes, + // to avoid building it again for each requested index + std::vector>& getCachedPropertyNamedList(DocumentObject* obj) const { + if (!this->namedPropsCache.contains(obj)) + { + this->namedPropsCache[obj]; + obj->getPropertyNamedList(this->namedPropsCache[obj]); + } + return this->namedPropsCache[obj]; + } + // The completion tree structure created takes into account the current document and object // // It is done as such: @@ -311,7 +322,6 @@ public: int docSize = (int)docs.size() * 2; int objSize = 0; int propSize = 0; - std::vector> props; App::Document* doc = nullptr; App::DocumentObject* obj = nullptr; const char* propName = nullptr; @@ -361,7 +371,7 @@ public: row = idx; } // get the properties - cobj->getPropertyNamedList(props); + auto& props = this->getCachedPropertyNamedList(cobj); propSize = (int)props.size(); // if this is an invalid index, bail out @@ -469,7 +479,7 @@ public: } if (!propName) { idx = info.prop < 0 ? row : info.prop; - obj->getPropertyNamedList(props); + auto& props = this->getCachedPropertyNamedList(obj); propSize = (int)props.size(); // return if the property is invalid if (idx < 0 || idx >= propSize) { @@ -522,7 +532,6 @@ public: } } } - return; } QModelIndex parent(const QModelIndex& index) const override @@ -682,6 +691,7 @@ public: } private: + mutable std::map>> namedPropsCache; std::set inList; std::string currentDoc; std::string currentObj; From 78f38d5c15f3d72d780c77779da739ef47b78e3f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 24 Jan 2026 21:23:34 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/Gui/ExpressionCompleter.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Gui/ExpressionCompleter.cpp b/src/Gui/ExpressionCompleter.cpp index 7f026792f2..16f82ddb62 100644 --- a/src/Gui/ExpressionCompleter.cpp +++ b/src/Gui/ExpressionCompleter.cpp @@ -288,9 +288,11 @@ public: // Store named object property list in cache for performance purposes, // to avoid building it again for each requested index - std::vector>& getCachedPropertyNamedList(DocumentObject* obj) const { - if (!this->namedPropsCache.contains(obj)) - { + std::vector>& getCachedPropertyNamedList( + DocumentObject* obj + ) const + { + if (!this->namedPropsCache.contains(obj)) { this->namedPropsCache[obj]; obj->getPropertyNamedList(this->namedPropsCache[obj]); }