QPair<QRunnable*, int> is too large for QList to be efficient-ish.
Qt3D is making heavy use of this, causing the QList node allocations to be among the top 10 per frame allocation sources. Switching to QVector fixes that. Change-Id: I3b4df329710f82bf8d6797ea1f0c79b288a08063 Reviewed-by: Sean Harmer <sean.harmer@kdab.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
d3fe4f066f
commit
eb0b03c579
@ -204,8 +204,8 @@ void QThreadPoolPrivate::enqueueTask(QRunnable *runnable, int priority)
|
||||
++runnable->ref;
|
||||
|
||||
// put it on the queue
|
||||
QList<QPair<QRunnable *, int> >::const_iterator begin = queue.constBegin();
|
||||
QList<QPair<QRunnable *, int> >::const_iterator it = queue.constEnd();
|
||||
QVector<QPair<QRunnable *, int> >::const_iterator begin = queue.constBegin();
|
||||
QVector<QPair<QRunnable *, int> >::const_iterator it = queue.constEnd();
|
||||
if (it != begin && priority > (*(it - 1)).second)
|
||||
it = std::upper_bound(begin, --it, priority);
|
||||
queue.insert(it - begin, qMakePair(runnable, priority));
|
||||
@ -299,7 +299,7 @@ bool QThreadPoolPrivate::waitForDone(int msecs)
|
||||
void QThreadPoolPrivate::clear()
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
for (QList<QPair<QRunnable *, int> >::const_iterator it = queue.constBegin();
|
||||
for (QVector<QPair<QRunnable *, int> >::const_iterator it = queue.constBegin();
|
||||
it != queue.constEnd(); ++it) {
|
||||
QRunnable* r = it->first;
|
||||
if (r->autoDelete() && !--r->ref)
|
||||
@ -319,8 +319,8 @@ bool QThreadPoolPrivate::stealRunnable(QRunnable *runnable)
|
||||
return false;
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
QList<QPair<QRunnable *, int> >::iterator it = queue.begin();
|
||||
QList<QPair<QRunnable *, int> >::iterator end = queue.end();
|
||||
QVector<QPair<QRunnable *, int> >::iterator it = queue.begin();
|
||||
QVector<QPair<QRunnable *, int> >::iterator end = queue.end();
|
||||
|
||||
while (it != end) {
|
||||
if (it->first == runnable) {
|
||||
|
@ -83,7 +83,7 @@ public:
|
||||
QSet<QThreadPoolThread *> allThreads;
|
||||
QQueue<QThreadPoolThread *> waitingThreads;
|
||||
QQueue<QThreadPoolThread *> expiredThreads;
|
||||
QList<QPair<QRunnable *, int> > queue;
|
||||
QVector<QPair<QRunnable *, int> > queue;
|
||||
QWaitCondition noActiveThreads;
|
||||
|
||||
bool isExiting;
|
||||
|
Loading…
Reference in New Issue
Block a user