Skip to content

Commit

Permalink
Revert "Fix massive performance regression in attribute table"
Browse files Browse the repository at this point in the history
This reverts commit 5fdb88b.
  • Loading branch information
3nids committed Jun 18, 2021
1 parent d17f591 commit 0c1f4f6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
Expand Up @@ -11,6 +11,7 @@




class QgsVectorLayerCache : QObject
{
%Docstring(signature="appended")
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgscachedfeatureiterator.cpp
Expand Up @@ -53,7 +53,7 @@ QgsCachedFeatureIterator::QgsCachedFeatureIterator( QgsVectorLayerCache *vlCache
break;

default:
mFeatureIds = QList( mVectorLayerCache->mCacheOrderedKeys.begin(), mVectorLayerCache->mCacheOrderedKeys.end() );
mFeatureIds = mVectorLayerCache->mCacheOrderedKeys;
break;
}

Expand Down
19 changes: 2 additions & 17 deletions src/core/vector/qgsvectorlayercache.cpp
Expand Up @@ -177,15 +177,7 @@ bool QgsVectorLayerCache::removeCachedFeature( QgsFeatureId fid )
{
bool removed = mCache.remove( fid );
if ( removed )
{
if ( auto unorderedIt = std::find( mCacheUnorderedKeys.begin(), mCacheUnorderedKeys.end(), fid ); unorderedIt != mCacheUnorderedKeys.end() )
{
mCacheUnorderedKeys.erase( unorderedIt );

if ( auto orderedIt = std::find( mCacheOrderedKeys.begin(), mCacheOrderedKeys.end(), fid ); orderedIt != mCacheOrderedKeys.end() )
mCacheOrderedKeys.erase( orderedIt );
}
}
mCacheOrderedKeys.removeOne( fid );
return removed;
}

Expand Down Expand Up @@ -278,13 +270,7 @@ void QgsVectorLayerCache::onJoinAttributeValueChanged( QgsFeatureId fid, int fie
void QgsVectorLayerCache::featureDeleted( QgsFeatureId fid )
{
mCache.remove( fid );

if ( auto it = mCacheUnorderedKeys.find( fid ); it != mCacheUnorderedKeys.end() )
{
mCacheUnorderedKeys.erase( it );
if ( auto orderedIt = std::find( mCacheOrderedKeys.begin(), mCacheOrderedKeys.end(), fid ); orderedIt != mCacheOrderedKeys.end() )
mCacheOrderedKeys.erase( orderedIt );
}
mCacheOrderedKeys.removeOne( fid );
}

void QgsVectorLayerCache::onFeatureAdded( QgsFeatureId fid )
Expand Down Expand Up @@ -344,7 +330,6 @@ void QgsVectorLayerCache::invalidate()
{
mCache.clear();
mCacheOrderedKeys.clear();
mCacheUnorderedKeys.clear();
mFullCache = false;
emit invalidated();
}
Expand Down
17 changes: 4 additions & 13 deletions src/core/vector/qgsvectorlayercache.h
Expand Up @@ -24,8 +24,7 @@
#include "qgsfield.h"
#include "qgsfeaturerequest.h"
#include "qgsfeatureiterator.h"
#include <unordered_set>
#include <deque>

#include <QCache>

class QgsVectorLayer;
Expand Down Expand Up @@ -394,21 +393,13 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
{
QgsCachedFeature *cachedFeature = new QgsCachedFeature( feat, this );
mCache.insert( feat.id(), cachedFeature );
if ( mCacheUnorderedKeys.find( feat.id() ) == mCacheUnorderedKeys.end() )
{
mCacheUnorderedKeys.insert( feat.id() );
mCacheOrderedKeys.emplace_back( feat.id() );
}
if ( !mCacheOrderedKeys.contains( feat.id() ) )
mCacheOrderedKeys << feat.id();
}

QgsVectorLayer *mLayer = nullptr;
QCache< QgsFeatureId, QgsCachedFeature > mCache;

// we need two containers here. One is used for efficient tracking of the IDs which have been added to the cache, the other
// is used to store the order of the incoming feature ids, so that we can correctly iterate through features in the original order.
// the ordered list alone is far too slow to handle this -- searching for existing items in a list is magnitudes slower than the unordered_set
std::unordered_set< QgsFeatureId > mCacheUnorderedKeys;
std::deque< QgsFeatureId > mCacheOrderedKeys;
QList< QgsFeatureId > mCacheOrderedKeys;

bool mCacheGeometry = true;
bool mFullCache = false;
Expand Down

0 comments on commit 0c1f4f6

Please sign in to comment.