diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-07-28 22:29:35 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-07-28 22:29:35 +0200 |
commit | a24bf3db83d81d7d7677a1f0f750f208d32998a8 (patch) | |
tree | 0d3fa9da24d706c2e6b03e8bf0fd74a434ae871f /common/typeindex.cpp | |
parent | 683ee2ec1d198a9f19572e42d78fa0b9939d7f10 (diff) | |
download | sink-a24bf3db83d81d7d7677a1f0f750f208d32998a8.tar.gz sink-a24bf3db83d81d7d7677a1f0f750f208d32998a8.zip |
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).
Diffstat (limited to 'common/typeindex.cpp')
-rw-r--r-- | common/typeindex.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/common/typeindex.cpp b/common/typeindex.cpp index 47512e8..646a60f 100644 --- a/common/typeindex.cpp +++ b/common/typeindex.cpp | |||
@@ -265,10 +265,10 @@ void TypeIndex::remove(const Identifier &identifier, const Sink::ApplicationDoma | |||
265 | } | 265 | } |
266 | } | 266 | } |
267 | 267 | ||
268 | static QVector<QByteArray> indexLookup(Index &index, QueryBase::Comparator filter, | 268 | static QVector<Identifier> indexLookup(Index &index, QueryBase::Comparator filter, |
269 | std::function<QByteArray(const QVariant &)> valueToKey = getByteArray) | 269 | std::function<QByteArray(const QVariant &)> valueToKey = getByteArray) |
270 | { | 270 | { |
271 | QVector<QByteArray> keys; | 271 | QVector<Identifier> keys; |
272 | QByteArrayList lookupKeys; | 272 | QByteArrayList lookupKeys; |
273 | if (filter.comparator == Query::Comparator::Equals) { | 273 | if (filter.comparator == Query::Comparator::Equals) { |
274 | lookupKeys << valueToKey(filter.value); | 274 | lookupKeys << valueToKey(filter.value); |
@@ -283,7 +283,7 @@ static QVector<QByteArray> indexLookup(Index &index, QueryBase::Comparator filte | |||
283 | for (const auto &lookupKey : lookupKeys) { | 283 | for (const auto &lookupKey : lookupKeys) { |
284 | index.lookup(lookupKey, | 284 | index.lookup(lookupKey, |
285 | [&](const QByteArray &value) { | 285 | [&](const QByteArray &value) { |
286 | keys << Identifier::fromInternalByteArray(value).toDisplayByteArray(); | 286 | keys << Identifier::fromInternalByteArray(value); |
287 | }, | 287 | }, |
288 | [lookupKey](const Index::Error &error) { | 288 | [lookupKey](const Index::Error &error) { |
289 | SinkWarning() << "Lookup error in index: " << error.message << lookupKey; | 289 | SinkWarning() << "Lookup error in index: " << error.message << lookupKey; |
@@ -293,7 +293,7 @@ static QVector<QByteArray> indexLookup(Index &index, QueryBase::Comparator filte | |||
293 | return keys; | 293 | return keys; |
294 | } | 294 | } |
295 | 295 | ||
296 | static QVector<QByteArray> sortedIndexLookup(Index &index, QueryBase::Comparator filter) | 296 | static QVector<Identifier> sortedIndexLookup(Index &index, QueryBase::Comparator filter) |
297 | { | 297 | { |
298 | if (filter.comparator == Query::Comparator::In || filter.comparator == Query::Comparator::Contains) { | 298 | if (filter.comparator == Query::Comparator::In || filter.comparator == Query::Comparator::Contains) { |
299 | SinkWarning() << "In and Contains comparison not supported on sorted indexes"; | 299 | SinkWarning() << "In and Contains comparison not supported on sorted indexes"; |
@@ -303,7 +303,7 @@ static QVector<QByteArray> sortedIndexLookup(Index &index, QueryBase::Comparator | |||
303 | return indexLookup(index, filter, toSortableByteArray); | 303 | return indexLookup(index, filter, toSortableByteArray); |
304 | } | 304 | } |
305 | 305 | ||
306 | QVector<QByteArray> keys; | 306 | QVector<Identifier> keys; |
307 | 307 | ||
308 | QByteArray lowerBound, upperBound; | 308 | QByteArray lowerBound, upperBound; |
309 | auto bounds = filter.value.value<QVariantList>(); | 309 | auto bounds = filter.value.value<QVariantList>(); |
@@ -318,7 +318,7 @@ static QVector<QByteArray> sortedIndexLookup(Index &index, QueryBase::Comparator | |||
318 | 318 | ||
319 | index.rangeLookup(lowerBound, upperBound, | 319 | index.rangeLookup(lowerBound, upperBound, |
320 | [&](const QByteArray &value) { | 320 | [&](const QByteArray &value) { |
321 | keys << Identifier::fromInternalByteArray(value).toDisplayByteArray(); | 321 | keys << Identifier::fromInternalByteArray(value); |
322 | }, | 322 | }, |
323 | [bounds](const Index::Error &error) { | 323 | [bounds](const Index::Error &error) { |
324 | SinkWarning() << "Lookup error in index:" << error.message | 324 | SinkWarning() << "Lookup error in index:" << error.message |
@@ -328,14 +328,14 @@ static QVector<QByteArray> sortedIndexLookup(Index &index, QueryBase::Comparator | |||
328 | return keys; | 328 | return keys; |
329 | } | 329 | } |
330 | 330 | ||
331 | static QVector<QByteArray> sampledIndexLookup(Index &index, QueryBase::Comparator filter) | 331 | static QVector<Identifier> sampledIndexLookup(Index &index, QueryBase::Comparator filter) |
332 | { | 332 | { |
333 | if (filter.comparator != Query::Comparator::Overlap) { | 333 | if (filter.comparator != Query::Comparator::Overlap) { |
334 | SinkWarning() << "Comparisons other than Overlap not supported on sampled period indexes"; | 334 | SinkWarning() << "Comparisons other than Overlap not supported on sampled period indexes"; |
335 | return {}; | 335 | return {}; |
336 | } | 336 | } |
337 | 337 | ||
338 | QVector<QByteArray> keys; | 338 | QVector<Identifier> keys; |
339 | 339 | ||
340 | auto bounds = filter.value.value<QVariantList>(); | 340 | auto bounds = filter.value.value<QVariantList>(); |
341 | 341 | ||
@@ -349,7 +349,7 @@ static QVector<QByteArray> sampledIndexLookup(Index &index, QueryBase::Comparato | |||
349 | 349 | ||
350 | index.rangeLookup(lowerBucket, upperBucket, | 350 | index.rangeLookup(lowerBucket, upperBucket, |
351 | [&](const QByteArray &value) { | 351 | [&](const QByteArray &value) { |
352 | keys << Identifier::fromInternalByteArray(value).toDisplayByteArray(); | 352 | keys << Identifier::fromInternalByteArray(value); |
353 | }, | 353 | }, |
354 | [bounds](const Index::Error &error) { | 354 | [bounds](const Index::Error &error) { |
355 | SinkWarning() << "Lookup error in index:" << error.message | 355 | SinkWarning() << "Lookup error in index:" << error.message |
@@ -359,13 +359,18 @@ static QVector<QByteArray> sampledIndexLookup(Index &index, QueryBase::Comparato | |||
359 | return keys; | 359 | return keys; |
360 | } | 360 | } |
361 | 361 | ||
362 | QVector<QByteArray> TypeIndex::query(const Sink::QueryBase &query, QSet<QByteArrayList> &appliedFilters, QByteArray &appliedSorting, Sink::Storage::DataStore::Transaction &transaction, const QByteArray &resourceInstanceId) | 362 | QVector<Identifier> TypeIndex::query(const Sink::QueryBase &query, QSet<QByteArrayList> &appliedFilters, QByteArray &appliedSorting, Sink::Storage::DataStore::Transaction &transaction, const QByteArray &resourceInstanceId) |
363 | { | 363 | { |
364 | const auto baseFilters = query.getBaseFilters(); | 364 | const auto baseFilters = query.getBaseFilters(); |
365 | for (auto it = baseFilters.constBegin(); it != baseFilters.constEnd(); it++) { | 365 | for (auto it = baseFilters.constBegin(); it != baseFilters.constEnd(); it++) { |
366 | if (it.value().comparator == QueryBase::Comparator::Fulltext) { | 366 | if (it.value().comparator == QueryBase::Comparator::Fulltext) { |
367 | FulltextIndex fulltextIndex{resourceInstanceId}; | 367 | FulltextIndex fulltextIndex{resourceInstanceId}; |
368 | const auto keys = fulltextIndex.lookup(it.value().value.toString()); | 368 | QVector<Identifier> keys; |
369 | const auto ids = fulltextIndex.lookup(it.value().value.toString()); | ||
370 | keys.reserve(ids.size()); | ||
371 | for (const auto &id : ids) { | ||
372 | keys.append(Identifier::fromDisplayByteArray(id)); | ||
373 | } | ||
369 | appliedFilters << it.key(); | 374 | appliedFilters << it.key(); |
370 | SinkTraceCtx(mLogCtx) << "Fulltext index lookup found " << keys.size() << " keys."; | 375 | SinkTraceCtx(mLogCtx) << "Fulltext index lookup found " << keys.size() << " keys."; |
371 | return keys; | 376 | return keys; |