[polari/join-room-list: 1/3] serverRoomManager: Limit time spend in idle handler



commit 11b3dd1689bd8f6f95f5e4a1f7288603fc4df23e
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Oct 21 18:50:56 2017 +0200

    serverRoomManager: Limit time spend in idle handler
    
    The number of available rooms can be fairly large (*cough* Freenode
    *cough*), so we currently insert rooms in chunks of 100 to make sure
    that we don't block the mainloop while loading the list. We still suffer
    from significant slow-down though, and Bastien Nocera pointed out that
    instead of inserting a fixed number of rows, we should limit the time
    spent in the idle handler to make sure that each frame still has enough
    cycles for drawing.
    
    Fixes https://gitlab.gnome.org/GNOME/polari/issues/13

 src/serverRoomManager.js | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/src/serverRoomManager.js b/src/serverRoomManager.js
index 78004f3..a55f5ca 100644
--- a/src/serverRoomManager.js
+++ b/src/serverRoomManager.js
@@ -12,7 +12,7 @@ const RoomManager = imports.roomManager;
 const Signals = imports.signals;
 const Utils = imports.utils;
 
-const LIST_CHUNK_SIZE = 100;
+const MS_PER_IDLE = 10; // max time spend in idle
 
 let _singleton = null;
 
@@ -319,16 +319,18 @@ var ServerRoomList = new Lang.Class({
         this._idleId = Mainloop.idle_add(() => {
             let customName = this._store.get_value(this._customRoomItem,
                                                    RoomListColumn.NAME);
-            this._pendingInfos.splice(0, LIST_CHUNK_SIZE).forEach(roomInfo => {
-                let store = this._store;
+            let store = this._store;
+            let startTime = GLib.get_monotonic_time();
+            while (this._pendingInfos.length > 0) {
+                let roomInfo = this._pendingInfos.shift();
 
                 let name = roomInfo.get_name();
                 if (name[0] == '#')
                     name = name.substr(1, name.length);
 
                 if (_strBaseEqual(name, customName))
-                    this._store.set_value(this._customRoomItem,
-                                          RoomListColumn.NAME, customName = '');
+                    store.set_value(this._customRoomItem,
+                                    RoomListColumn.NAME, customName = '');
 
                 let room = roomManager.lookupRoomByName(roomInfo.get_name(), this._account);
                 let sensitive = room == null;
@@ -342,9 +344,11 @@ var ServerRoomList = new Lang.Class({
                                                       RoomListColumn.SENSITIVE],
                                                      [checked, name, count, sensitive]);
                 store.move_before(iter, this._customRoomItem);
-            });
-            if (this._pendingInfos.length)
-                return GLib.SOURCE_CONTINUE;
+
+                // Limit time spent in idle to leave room for drawing etc.
+                if (GLib.get_monotonic_time() - startTime > 1000 * MS_PER_IDLE)
+                    return GLib.SOURCE_CONTINUE;
+            }
 
             this._idleId = 0;
             this._checkSpinner();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]