aboutsummaryrefslogtreecommitdiffstats
path: root/src/particles/qquickparticlesystem_p.h
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-05-19 14:43:49 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-05-27 16:25:56 +0200
commit27c0034d6bb0df50d4479e42fc82fcd74b03d810 (patch)
treefe5daa30e19287d79d5701fcdc90fe09fc1f786b /src/particles/qquickparticlesystem_p.h
parent5ce2d540be875041b38b481e3caef295071c79ee (diff)
Particles: reduce memory allocations by flattening a set
When an affector acts on a particle, it will add it to a set of "seen" particles. This means an allocation, per particle, per frame. In Qt 6 the problem is less dramatic due to the new QHash implementation, which uses "wider" buckets, but in Qt 5 this is hundreds of memory allocations (and deallocations) per frame. Just reimplement a minimal flat-set API for this use case, and replace the QSet usages with it. On a testcase with 200 active particles, this reduces memory allocations from ~20'000 per second to 0 when the scene is "stable". Pick-to: 5.15 Change-Id: I4be1e12a23b8dffca91955148532db243e383a4c Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/particles/qquickparticlesystem_p.h')
-rw-r--r--src/particles/qquickparticlesystem_p.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/particles/qquickparticlesystem_p.h b/src/particles/qquickparticlesystem_p.h
index b7812c6ea5..b1053d8ff8 100644
--- a/src/particles/qquickparticlesystem_p.h
+++ b/src/particles/qquickparticlesystem_p.h
@@ -63,6 +63,7 @@
#include <private/qv4global_p.h>
#include <private/qv4staticvalue_p.h>
#include "qtquickparticlesglobal_p.h"
+#include "qquickparticleflatset_p.h"
QT_BEGIN_NAMESPACE
@@ -410,7 +411,7 @@ public:
int systemSync(QQuickParticlePainter* p);
//Data members here for ease of related class and auto-test usage. Not "public" API. TODO: d_ptrize
- QSet<QQuickParticleData*> needsReset;
+ QtQuickParticlesPrivate::QFlatSet<QQuickParticleData*> needsReset;
QVector<QQuickParticleData*> bySysIdx; //Another reference to the data (data owned by group), but by sysIdx
QQuickStochasticEngine* stateEngine;