aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-05-20 09:43:52 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-05-20 13:19:25 +0200
commit5bb746520db70b09de463f0ce27ecfbe3e5dfb4f (patch)
tree932a287c2e834dfcb4fb83839fcb10b4f8a50b6d /src
parentae1334d827bd386ae34ed5fca8f00dcef83bc65e (diff)
Use QHash instead of QMap for resolved types
This vastly speeds up resolved type reference lookups in QQmlObjectCreator::createInstance, which translates to significant improvements in qmlbench: perf record -b ./src/qmlbench --shell frame-count delegates_qobject.qml went from roughly 730 frames to > 800 locally. To have a stable order in the hash, we simply sort a tempory vector of keys. As this happens only once, the overhead is negligible and partially offset by the better memory locality of the QHash anyway. Task-number: QTBUG-88672 Change-Id: Ib547a87fd0d2d81f366ea927ade232f33b3d3788 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/jsruntime/qv4executablecompilationunit.cpp14
-rw-r--r--src/qml/jsruntime/qv4executablecompilationunit_p.h4
2 files changed, 14 insertions, 4 deletions
diff --git a/src/qml/jsruntime/qv4executablecompilationunit.cpp b/src/qml/jsruntime/qv4executablecompilationunit.cpp
index f61bf36b0e..ade5204f9e 100644
--- a/src/qml/jsruntime/qv4executablecompilationunit.cpp
+++ b/src/qml/jsruntime/qv4executablecompilationunit.cpp
@@ -865,10 +865,22 @@ bool ExecutableCompilationUnit::saveToDisk(const QUrl &unitUrl, QString *errorSt
});
}
+/*!
+ \internal
+ This function creates a temporary key vector and sorts it to guarantuee a stable
+ hash. This is used to calculate a check-sum on dependent meta-objects.
+ */
bool ResolvedTypeReferenceMap::addToHash(QCryptographicHash *hash, QQmlEngine *engine) const
{
+ std::vector<int> keys (count());
+ int i = 0;
for (auto it = constBegin(), end = constEnd(); it != end; ++it) {
- if (!it.value()->addToHash(hash, engine))
+ keys[i] = it.key();
+ ++i;
+ }
+ std::sort(keys.begin(), keys.end());
+ for (int key: keys) {
+ if (!this->operator[](key)->addToHash(hash, engine))
return false;
}
diff --git a/src/qml/jsruntime/qv4executablecompilationunit_p.h b/src/qml/jsruntime/qv4executablecompilationunit_p.h
index 3dc0e58ca5..9ceec1fbf7 100644
--- a/src/qml/jsruntime/qv4executablecompilationunit_p.h
+++ b/src/qml/jsruntime/qv4executablecompilationunit_p.h
@@ -92,9 +92,7 @@ typedef QVector<QQmlPropertyData*> BindingPropertyData;
class CompilationUnitMapper;
class ResolvedTypeReference;
// map from name index
-// While this could be a hash, a map is chosen here to provide a stable
-// order, which is used to calculating a check-sum on dependent meta-objects.
-struct ResolvedTypeReferenceMap: public QMap<int, ResolvedTypeReference*>
+struct ResolvedTypeReferenceMap: public QHash<int, ResolvedTypeReference*>
{
bool addToHash(QCryptographicHash *hash, QQmlEngine *engine) const;
};