From 6f3aaecb783c5d8b9dc82cb9752ec4d0372a3b9c Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Fri, 17 Jun 2016 19:04:24 +0200 Subject: [PATCH 1/4] Fix a crash on if shutting down during propagation The SyncRunFileLog owned by the Folder must be destroyed after the SyncEngine since the SyncEngine will abort during destruction, resulting in all jobs being aborted. It's possible that this crash only happens with a debug build. --- src/gui/folder.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 0a88c68c9..ac50c7f06 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -121,6 +121,8 @@ Folder::Folder(const FolderDefinition& definition, Folder::~Folder() { + // Reset then engine first as it will abort and try to access members of the Folder + _engine.reset(); } void Folder::checkLocalPath() From 87e3553c850348721bd371b32d72bfbb55b58586 Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Fri, 17 Jun 2016 19:06:39 +0200 Subject: [PATCH 2/4] Prevent the sync protocol widget from over-using memory During propagation, we create a line for each file, taking memory, but we delete all lines passed 2000 right at the beginning of the next sync. Since the user has little chances of being able to read past those 2000 lines in the log, we might as well keep it capped at 2000 also during propagation to prevent it from eating memory. --- src/gui/protocolwidget.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/gui/protocolwidget.cpp b/src/gui/protocolwidget.cpp index c96fa1de3..8955dc7b7 100644 --- a/src/gui/protocolwidget.cpp +++ b/src/gui/protocolwidget.cpp @@ -121,17 +121,9 @@ void ProtocolWidget::hideEvent(QHideEvent *ev) void ProtocolWidget::cleanItems(const QString& folder) { - int itemCnt = _ui->_treeWidget->topLevelItemCount(); - - // Limit the number of items - while(itemCnt > 2000) { - delete _ui->_treeWidget->takeTopLevelItem(itemCnt - 1); - itemCnt--; - } - // The issue list is a state, clear it and let the next sync fill it // with ignored files and propagation errors. - itemCnt = _issueItemView->topLevelItemCount(); + int itemCnt = _issueItemView->topLevelItemCount(); for( int cnt = itemCnt-1; cnt >=0 ; cnt-- ) { QTreeWidgetItem *item = _issueItemView->topLevelItem(cnt); QString itemFolder = item->data(2, Qt::UserRole).toString(); @@ -239,6 +231,12 @@ void ProtocolWidget::slotItemCompleted(const QString &folder, const SyncFileItem _issueItemView->insertTopLevelItem(0, line); emit issueItemCountUpdated(_issueItemView->topLevelItemCount()); } else { + // Limit the number of items + int itemCnt = _ui->_treeWidget->topLevelItemCount(); + while(itemCnt > 2000) { + delete _ui->_treeWidget->takeTopLevelItem(itemCnt - 1); + itemCnt--; + } _ui->_treeWidget->insertTopLevelItem(0, line); } } From 7fb134b4e05df834b94e82c40bc9d7f96396be65 Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Fri, 17 Jun 2016 19:08:04 +0200 Subject: [PATCH 3/4] Delete the ComputeChecksum object when the job is finished Each object takes almost 1k and we don't need it once the propagation is done. --- src/libsync/propagateupload.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index 5875ae739..795a2f2e9 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -234,6 +234,8 @@ void PropagateUploadFileQNAM::slotComputeContentChecksum() connect(computeChecksum, SIGNAL(done(QByteArray,QByteArray)), SLOT(slotComputeTransmissionChecksum(QByteArray,QByteArray))); + connect(computeChecksum, SIGNAL(done(QByteArray,QByteArray)), + computeChecksum, SLOT(deleteLater())); computeChecksum->start(filePath); } @@ -268,6 +270,8 @@ void PropagateUploadFileQNAM::slotComputeTransmissionChecksum(const QByteArray& connect(computeChecksum, SIGNAL(done(QByteArray,QByteArray)), SLOT(slotStartUpload(QByteArray,QByteArray))); + connect(computeChecksum, SIGNAL(done(QByteArray,QByteArray)), + computeChecksum, SLOT(deleteLater())); const QString filePath = _propagator->getFilePath(_item->_file); computeChecksum->start(filePath); } From edfd75949dbb978486f4826d9ee8179e7655fa1b Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Fri, 17 Jun 2016 19:09:37 +0200 Subject: [PATCH 4/4] Reduce the memory usage of the StopWatch during propagation Use a QMap to avoid using a full hashtable for only a few entries, and clear the QMap once we're done with the measuring. This saves a few hundred bytes per job during propagation that would otherwise only be freed at the end of the sync. --- src/libsync/propagateupload.cpp | 2 ++ src/libsync/utility.h | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index 795a2f2e9..f60106244 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -779,6 +779,8 @@ void PropagateUploadFileQNAM::slotPutFinished() << _stopWatch.durationOfLap(QLatin1String("ContentChecksum")) << _stopWatch.durationOfLap(QLatin1String("TransmissionChecksum")) << _item->_requestDuration; + // The job might stay alive for the whole sync, release this tiny bit of memory. + _stopWatch.reset(); finalize(*_item); } diff --git a/src/libsync/utility.h b/src/libsync/utility.h index 044988fe1..6dd2f1788 100644 --- a/src/libsync/utility.h +++ b/src/libsync/utility.h @@ -20,7 +20,7 @@ #include #include #include -#include +#include namespace OCC { @@ -121,7 +121,7 @@ namespace Utility class OWNCLOUDSYNC_EXPORT StopWatch { private: - QHash _lapTimes; + QMap _lapTimes; QDateTime _startTime; QElapsedTimer _timer; public: