From a24bf3db83d81d7d7677a1f0f750f208d32998a8 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 28 Jul 2018 22:29:35 +0200 Subject: Avoid unnecessary Identifier conversions in performance ciritical code. This fixes the performance regressions to a state where we are roughly at the same performance as pre Identifier (but not any better either). --- common/storage/entitystore.cpp | 12 ++++++------ common/storage/entitystore.h | 4 ++-- common/storage/key.cpp | 6 ++++++ common/storage/key.h | 2 ++ 4 files changed, 16 insertions(+), 8 deletions(-) (limited to 'common/storage') diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 71690fe..1ba7c6c 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp @@ -426,19 +426,19 @@ bool EntityStore::cleanupRevisions(qint64 revision) return cleanupIsNecessary; } -QVector EntityStore::fullScan(const QByteArray &type) +QVector EntityStore::fullScan(const QByteArray &type) { SinkTraceCtx(d->logCtx) << "Looking for : " << type; if (!d->exists()) { SinkTraceCtx(d->logCtx) << "Database is not existing: " << type; - return QVector(); + return {}; } //The scan can return duplicate results if we have multiple revisions, so we use a set to deduplicate. - QSet keys; + QSet keys; DataStore::mainDatabase(d->getTransaction(), type) .scan(QByteArray(), [&](const QByteArray &key, const QByteArray &value) -> bool { - const auto uid = Sink::Storage::Key::fromInternalByteArray(key).identifier().toDisplayByteArray(); + const auto uid = Sink::Storage::Key::fromInternalByteArray(key).identifier(); if (keys.contains(uid)) { //Not something that should persist if the replay works, so we keep a message for now. SinkTraceCtx(d->logCtx) << "Multiple revisions for key: " << key; @@ -452,11 +452,11 @@ QVector EntityStore::fullScan(const QByteArray &type) return keys.toList().toVector(); } -QVector EntityStore::indexLookup(const QByteArray &type, const QueryBase &query, QSet &appliedFilters, QByteArray &appliedSorting) +QVector EntityStore::indexLookup(const QByteArray &type, const QueryBase &query, QSet &appliedFilters, QByteArray &appliedSorting) { if (!d->exists()) { SinkTraceCtx(d->logCtx) << "Database is not existing: " << type; - return QVector(); + return {}; } return d->typeIndex(type).query(query, appliedFilters, appliedSorting, d->getTransaction(), d->resourceContext.instanceId()); } diff --git a/common/storage/entitystore.h b/common/storage/entitystore.h index 619b884..7979798 100644 --- a/common/storage/entitystore.h +++ b/common/storage/entitystore.h @@ -57,8 +57,8 @@ public: void abortTransaction(); bool hasTransaction() const; - QVector fullScan(const QByteArray &type); - QVector indexLookup(const QByteArray &type, const QueryBase &query, QSet &appliedFilters, QByteArray &appliedSorting); + QVector fullScan(const QByteArray &type); + QVector indexLookup(const QByteArray &type, const QueryBase &query, QSet &appliedFilters, QByteArray &appliedSorting); QVector indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value); void indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value, const std::function &callback); template diff --git a/common/storage/key.cpp b/common/storage/key.cpp index 23d7a6a..2327061 100644 --- a/common/storage/key.cpp +++ b/common/storage/key.cpp @@ -26,6 +26,12 @@ using Sink::Storage::Identifier; using Sink::Storage::Key; using Sink::Storage::Revision; + +uint Sink::Storage::qHash(const Sink::Storage::Identifier &identifier) +{ + return qHash(identifier.toInternalByteArray()); +} + QDebug &operator<<(QDebug &dbg, const Identifier &id) { dbg << id.toDisplayString(); diff --git a/common/storage/key.h b/common/storage/key.h index 211aea7..baabe38 100644 --- a/common/storage/key.h +++ b/common/storage/key.h @@ -119,6 +119,8 @@ private: Revision rev; }; +SINK_EXPORT uint qHash(const Sink::Storage::Identifier &); + } // namespace Storage } // namespace Sink -- cgit v1.2.3