Skip to content

Commit 6341f80

Browse files
committed
perf(discovery): avoid per-call QTimer heap allocation when scheduling jobs
Replace the 5 QTimer::singleShot(0, ...) calls that defer DiscoveryPhase::scheduleMoreJobs with QMetaObject::invokeMethod(Qt::QueuedConnection). Both achieve the same deferred (queued) invocation, but invokeMethod does not allocate a QTimer on the heap for each call. In a large sync with many directories this eliminates thousands of unnecessary heap allocations. Signed-off-by: Qoole <2862661+qoole@users.noreply.github.com>
1 parent 9ac8d75 commit 6341f80

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/libsync/discovery.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void ProcessDirectoryJob::process()
250250
processFile(std::move(path), e.localEntry, e.serverEntry, e.dbEntry);
251251
}
252252
_discoveryData->_listExclusiveFiles.clear();
253-
QTimer::singleShot(0, _discoveryData, &DiscoveryPhase::scheduleMoreJobs);
253+
QMetaObject::invokeMethod(_discoveryData, &DiscoveryPhase::scheduleMoreJobs, Qt::QueuedConnection);
254254
}
255255

256256
bool ProcessDirectoryJob::handleExcluded(const QString &path, const Entries &entries, const std::map<QString, Entries> &allEntries, const bool isHidden, const bool isBlacklisted)
@@ -699,7 +699,7 @@ void ProcessDirectoryJob::postProcessServerNew(const SyncFileItemPtr &item,
699699
if (!result) {
700700
processFileAnalyzeLocalInfo(item, path, localEntry, serverEntry, dbEntry, _queryServer);
701701
}
702-
QTimer::singleShot(0, _discoveryData, &DiscoveryPhase::scheduleMoreJobs);
702+
QMetaObject::invokeMethod(_discoveryData, &DiscoveryPhase::scheduleMoreJobs, Qt::QueuedConnection);
703703
});
704704
return;
705705
}
@@ -1063,7 +1063,7 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(const SyncFileItemPtr &it
10631063
const auto job = new RequestEtagJob(_discoveryData->_account, _discoveryData->_remoteFolder + originalPath, this);
10641064
connect(job, &RequestEtagJob::finishedWithResult, this, [=, this](const HttpResult<QByteArray> &etag) mutable {
10651065
_pendingAsyncJobs--;
1066-
QTimer::singleShot(0, _discoveryData, &DiscoveryPhase::scheduleMoreJobs);
1066+
QMetaObject::invokeMethod(_discoveryData, &DiscoveryPhase::scheduleMoreJobs, Qt::QueuedConnection);
10671067
if (etag || etag.error().code != 404 ||
10681068
// Somehow another item claimed this original path, consider as if it existed
10691069
_discoveryData->isRenamed(originalPath)) {
@@ -1714,7 +1714,7 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
17141714
}
17151715
processFileFinalize(item, path, item->isDirectory(), NormalQuery, recurseQueryServer);
17161716
_pendingAsyncJobs--;
1717-
QTimer::singleShot(0, _discoveryData, &DiscoveryPhase::scheduleMoreJobs);
1717+
QMetaObject::invokeMethod(_discoveryData, &DiscoveryPhase::scheduleMoreJobs, Qt::QueuedConnection);
17181718
});
17191719
job->start();
17201720
return;
@@ -2194,7 +2194,7 @@ void ProcessDirectoryJob::subJobFinished()
21942194
int count = _runningJobs.removeAll(job);
21952195
ASSERT(count == 1);
21962196
job->deleteLater();
2197-
QTimer::singleShot(0, _discoveryData, &DiscoveryPhase::scheduleMoreJobs);
2197+
QMetaObject::invokeMethod(_discoveryData, &DiscoveryPhase::scheduleMoreJobs, Qt::QueuedConnection);
21982198
}
21992199

22002200
int ProcessDirectoryJob::processSubJobs(int nbJobs)

0 commit comments

Comments
 (0)