From 23ccfc4b36a6a7c44cf1a4eb8973dfb7946df7f9 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 27 Nov 2017 09:12:14 +0100 Subject: [PATCH] Utils: Delay saving of treeview column sizes while resizing As discussed in the linked report, QSettings behavior was changed to aggressively attempt to sync on each ::setValue() call, therefore causing excessive disk thrashing when used regularly. This is arguably a regression on the QSettings side, specifically as the documentation suggests some kind of delay and therefore merging of quick sequences of setValue calls (as implemented previously), but since this opinion is not generally shared, Qt applications need to implement that behavior now by themselves. This patch here does that for the reported case in Creator (and uses the opportunity to delay to 2 secs, which should be sufficient for the case) Change-Id: I04af0cd1a042abcf7113b5dde5c36e0338f7acb3 Task-number: QTCREATORBUG-15594 Reviewed-by: Eike Ziller --- src/libs/utils/basetreeview.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libs/utils/basetreeview.cpp b/src/libs/utils/basetreeview.cpp index 29c531e1cc5..98b997c5c84 100644 --- a/src/libs/utils/basetreeview.cpp +++ b/src/libs/utils/basetreeview.cpp @@ -51,7 +51,11 @@ class BaseTreeViewPrivate : public QObject public: explicit BaseTreeViewPrivate(BaseTreeView *parent) : q(parent), m_settings(0), m_expectUserChanges(false), m_progressIndicator(0) - {} + { + m_settingsTimer.setSingleShot(true); + connect(&m_settingsTimer, &QTimer::timeout, + this, &BaseTreeViewPrivate::doSaveState); + } bool eventFilter(QObject *, QEvent *event) { @@ -102,6 +106,12 @@ public: void saveState() { + m_settingsTimer.start(2000); // Once per 2 secs should be enough. + } + + void doSaveState() + { + m_settingsTimer.stop(); if (m_settings && !m_settingsKey.isEmpty()) { m_settings->beginGroup(m_settingsKey); QVariantList l; @@ -210,6 +220,7 @@ public: BaseTreeView *q; QMap m_userHandled; // column -> width, "not present" means "automatic" QSettings *m_settings; + QTimer m_settingsTimer; QString m_settingsKey; bool m_expectUserChanges; ProgressIndicator *m_progressIndicator;