[gnome-shell] iconGrid: Get max child size using existing array of visible children



commit 0978b87e65233ebb02e14173ed155ca71ea060b9
Author: Jonas Dreßler <verdre v0yd nl>
Date:   Thu Feb 25 18:07:59 2021 +0100

    iconGrid: Get max child size using existing array of visible children
    
    Using a preexisting array to iterate over is much faster than iterating
    over the actors children using a "for ... of" loop, that's because the
    latter calls into C functions to get the next actor all the time.
    
    Also, stop using array deconstruction here, it turned out that this is
    extremely expensive. When profiling this part of the code, it turned out
    that only 9% of the time spent in _getChildrenMaxSize() is spent calling
    the get_preferred_height/width() methods. When not using array
    deconstruction, this time increased to 22%, still not great, but a lot
    better.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1713>

 js/ui/iconGrid.js | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
---
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index a06f92e573..30d9cdde31 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -420,15 +420,19 @@ var IconGridLayout = GObject.registerClass({
             let minWidth = 0;
             let minHeight = 0;
 
-            for (const child of this._container) {
-                if (!child.visible)
-                    continue;
-
-                const [childMinHeight] = child.get_preferred_height(-1);
-                const [childMinWidth] = child.get_preferred_width(-1);
-
-                minWidth = Math.max(minWidth, childMinWidth);
-                minHeight = Math.max(minHeight, childMinHeight);
+            const nPages = this._pages.length;
+            for (let pageIndex = 0; pageIndex < nPages; pageIndex++) {
+                const page = this._pages[pageIndex];
+                const nVisibleItems = page.visibleChildren.length;
+                for (let itemIndex = 0; itemIndex < nVisibleItems; itemIndex++) {
+                    const item = page.visibleChildren[itemIndex];
+
+                    const childMinHeight = item.get_preferred_height(-1)[0];
+                    const childMinWidth = item.get_preferred_width(-1)[0];
+
+                    minWidth = Math.max(minWidth, childMinWidth);
+                    minHeight = Math.max(minHeight, childMinHeight);
+                }
             }
 
             this._childrenMaxSize = Math.max(minWidth, minHeight);


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