[gnome-shell] windowPreview: Cache the boundingBox of the layout manager



commit 959639bdc9ba75bf3d85c7827f4519df957c99f2
Author: Jonas Dreßler <verdre v0yd nl>
Date:   Mon Feb 1 11:51:27 2021 +0100

    windowPreview: Cache the boundingBox of the layout manager
    
    Accessing GObject properties from JS has proven to be quite slow because
    of the JS->C->JS roundtrip involved. With the WindowPreview this
    actually has an impact since we're accessing those properties very often
    while creating new layouts.
    
    So cache the boundingBox and the windowCenter properties of the
    WindowPreview using a this._cachedBoundingBox JS object. This might
    speed up opening the overview with lots of open windows significantly.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1617>

 js/ui/windowPreview.js | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
---
diff --git a/js/ui/windowPreview.js b/js/ui/windowPreview.js
index 23a353ef5b..f6d1490a3d 100644
--- a/js/ui/windowPreview.js
+++ b/js/ui/windowPreview.js
@@ -231,8 +231,22 @@ var WindowPreview = GObject.registerClass({
 
         this._stackAbove = null;
 
+        this._cachedBoundingBox = {
+            x: this._windowContainer.layout_manager.bounding_box.x1,
+            y: this._windowContainer.layout_manager.bounding_box.y1,
+            width: this._windowContainer.layout_manager.bounding_box.get_width(),
+            height: this._windowContainer.layout_manager.bounding_box.get_height(),
+        };
+
         this._windowContainer.layout_manager.connect(
             'notify::bounding-box', layout => {
+                this._cachedBoundingBox = {
+                    x: layout.bounding_box.x1,
+                    y: layout.bounding_box.y1,
+                    width: layout.bounding_box.get_width(),
+                    height: layout.bounding_box.get_height(),
+                };
+
                 // A bounding box of 0x0 means all windows were removed
                 if (layout.bounding_box.get_area() > 0)
                     this.emit('size-changed');
@@ -561,23 +575,14 @@ var WindowPreview = GObject.registerClass({
     }
 
     get boundingBox() {
-        const box = this._windowContainer.layout_manager.bounding_box;
-
-        return {
-            x: box.x1,
-            y: box.y1,
-            width: box.get_width(),
-            height: box.get_height(),
-        };
+        return { ...this._cachedBoundingBox };
     }
 
     get windowCenter() {
-        const box = this._windowContainer.layout_manager.bounding_box;
-
-        return new Graphene.Point({
-            x: box.get_x() + box.get_width() / 2,
-            y: box.get_y() + box.get_height() / 2,
-        });
+        return {
+            x: this._cachedBoundingBox.x + this._cachedBoundingBox.width / 2,
+            y: this._cachedBoundingBox.y + this._cachedBoundingBox.height / 2,
+        };
     }
 
     // eslint-disable-next-line camelcase


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