Merge lp:~marcustomlinson/unity-scopes-shell/lp-1627795 into lp:unity-scopes-shell

Proposed by Marcus Tomlinson
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 346
Merged at revision: 349
Proposed branch: lp:~marcustomlinson/unity-scopes-shell/lp-1627795
Merge into: lp:unity-scopes-shell
Diff against target: 151 lines (+1/-28)
4 files modified
src/Unity/scope.cpp (+1/-9)
src/Unity/scope.h (+0/-2)
src/Unity/settingsmodel.cpp (+0/-15)
src/Unity/settingsmodel.h (+0/-2)
To merge this branch: bzr merge lp:~marcustomlinson/unity-scopes-shell/lp-1627795
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
unity-api-1-bot continuous-integration Needs Fixing
Review via email: mp+307523@code.launchpad.net

Commit message

Don't make changes to the settings model from a separate thread.

To post a comment you must log in.
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Hmmm... AFAIR the original change with QtConcurrent was introduced because of the measured (and actually noticable) delay related to child scopes update & resulting settings model update? Aren't we returning to this problem with such change?

How about instead of calling m_settingsModel->update_child_scopes(...) directly from the QtConcurrent's thread, we do this via a signal-slot or a custom QEvent?

review: Needs Information
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:346
https://jenkins.canonical.com/unity-api-1/job/lp-unity-scopes-shell-ci/2/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/832/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/839
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/646
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/646/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/646
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/646/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/646
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/646/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/646
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/646/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/646
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/646/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/646/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/646
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/646/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/646
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/646/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/646
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/646/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-unity-scopes-shell-ci/2/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

> Hmmm... AFAIR the original change with QtConcurrent was introduced because of
> the measured (and actually noticable) delay related to child scopes update &
> resulting settings model update? Aren't we returning to this problem with such
> change?
>
> How about instead of calling m_settingsModel->update_child_scopes(...)
> directly from the QtConcurrent's thread, we do this via a signal-slot or a
> custom QEvent?

No, we still retain most of the optimisation. See line 43 of the diff here: https://code.launchpad.net/~marcustomlinson/unity-scopes-shell/lp-1567429/+merge/291480

The main improvement that was introduced was a m_childScopesDirty flag that avoided us re-loading child scopes each time settings() was called.

Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

Got it building here: https://bileto.ubuntu.com/#/ticket/1785

I'll see if there is any noticeable performance hit.

Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

No noticeable loss in performance.

+ This still gives us the 0ms lag on settings() (which is what we fixed in the previous MP: Bug #1567429)

+ I still see that cool behaviour where the scope starts up quickly, then the settings cog appears as soon as child scopes are loaded.

Revision history for this message
Paweł Stołowski (stolowski) wrote :

Cool. This looks good to me, thanks! +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Unity/scope.cpp'
2--- src/Unity/scope.cpp 2016-06-24 14:03:59 +0000
3+++ src/Unity/scope.cpp 2016-10-04 08:08:33 +0000
4@@ -133,7 +133,6 @@
5
6 Scope::~Scope()
7 {
8- m_childScopesFuture.waitForFinished();
9 }
10
11 void Scope::processSearchChunk(PushEvent* pushEvent)
12@@ -964,14 +963,7 @@
13 // reset the flag so that re-entering this method won't restart the update unnecessarily
14 m_childScopesDirty = false;
15
16- // just in case we have another update still running, wait here for it to complete
17- m_childScopesFuture.waitForFinished();
18-
19- // run the update in a seperate thread
20- m_childScopesFuture = QtConcurrent::run([this]
21- {
22- m_settingsModel->update_child_scopes(m_scopesInstance->getAllMetadata());
23- });
24+ m_settingsModel->update_child_scopes(m_scopesInstance->getAllMetadata());
25 }
26 }
27
28
29=== modified file 'src/Unity/scope.h'
30--- src/Unity/scope.h 2016-06-23 09:27:45 +0000
31+++ src/Unity/scope.h 2016-10-04 08:08:33 +0000
32@@ -21,7 +21,6 @@
33 #define NG_SCOPE_H
34
35 // Qt
36-#include <QFuture>
37 #include <QObject>
38 #include <QString>
39 #include <QTimer>
40@@ -256,7 +255,6 @@
41 int m_cardinality;
42
43 bool m_childScopesDirty;
44- QFuture<void> m_childScopesFuture;
45
46 QMap<std::string, QList<std::shared_ptr<unity::scopes::CategorisedResult>>> m_category_results;
47 std::unique_ptr<CollectionController> m_searchController;
48
49=== modified file 'src/Unity/settingsmodel.cpp'
50--- src/Unity/settingsmodel.cpp 2016-05-30 07:08:49 +0000
51+++ src/Unity/settingsmodel.cpp 2016-10-04 08:08:33 +0000
52@@ -158,8 +158,6 @@
53
54 QVariant SettingsModel::data(const QModelIndex& index, int role) const
55 {
56- QMutexLocker locker(&m_mutex);
57-
58 int row = index.row();
59 QVariant result;
60
61@@ -255,8 +253,6 @@
62
63 QVariant SettingsModel::value(const QString& id) const
64 {
65- QMutexLocker locker(&m_mutex);
66-
67 // Check for the setting id in the child scopes list first, in case the
68 // aggregator is incorrectly using a scope id as a settings as well.
69 if (m_child_scopes_data_by_id.contains(id))
70@@ -313,8 +309,6 @@
71
72 void SettingsModel::update_child_scopes(QMap<QString, sc::ScopeMetadata::SPtr> const& scopes_metadata)
73 {
74- QMutexLocker locker(&m_mutex);
75-
76 if (!scopes_metadata.contains(m_scopeId) ||
77 !scopes_metadata[m_scopeId]->is_aggregator())
78 {
79@@ -369,15 +363,12 @@
80 endResetModel();
81 }
82
83- locker.unlock();
84 Q_EMIT countChanged();
85 }
86
87 bool SettingsModel::setData(const QModelIndex &index, const QVariant &value,
88 int role)
89 {
90- QMutexLocker locker(&m_mutex);
91-
92 int row = index.row();
93 QVariant result;
94
95@@ -441,20 +432,16 @@
96
97 int SettingsModel::count() const
98 {
99- QMutexLocker locker(&m_mutex);
100 return m_data.size() + m_child_scopes_data.size();
101 }
102
103 bool SettingsModel::require_child_scopes_refresh() const
104 {
105- QMutexLocker locker(&m_mutex);
106 return m_requireChildScopesRefresh;
107 }
108
109 void SettingsModel::settings_timeout()
110 {
111- QMutexLocker locker(&m_mutex);
112-
113 QObject *timer = sender();
114 if (!timer)
115 {
116@@ -478,7 +465,6 @@
117 {
118 m_scopeProxy->set_child_scopes(m_child_scopes);
119
120- locker.unlock();
121 Q_EMIT settingsChanged();
122 }
123 catch (std::exception const& e)
124@@ -514,7 +500,6 @@
125 FileLock lock = unixLock(m_settings_path, true);
126 m_settings->sync(); // make sure the change to setting value is synced to fs
127
128- locker.unlock();
129 Q_EMIT settingsChanged();
130 }
131 catch(const unity::FileException& e)
132
133=== modified file 'src/Unity/settingsmodel.h'
134--- src/Unity/settingsmodel.h 2016-05-30 07:08:49 +0000
135+++ src/Unity/settingsmodel.h 2016-10-04 08:08:33 +0000
136@@ -29,7 +29,6 @@
137
138 #include <QAbstractListModel>
139 #include <QList>
140-#include <QMutex>
141 #include <QSharedPointer>
142
143 QT_BEGIN_NAMESPACE
144@@ -95,7 +94,6 @@
145 void tryLoadSettings(bool read_only) const;
146
147 protected:
148- mutable QMutex m_mutex;
149 QString m_scopeId;
150 unity::scopes::ScopeProxy m_scopeProxy;
151 int m_settingsTimeout;

Subscribers

People subscribed via source and target branches

to all changes: