[gnome-shell] iconGrid: Cache max size of children
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] iconGrid: Cache max size of children
- Date: Wed, 3 Mar 2021 18:03:31 +0000 (UTC)
commit b3c46a33c0dd39a4257937a7ad12bc0cfb8813ef
Author: Jonas Dreßler <verdre v0yd nl>
Date: Tue Feb 23 19:47:45 2021 +0100
iconGrid: Cache max size of children
We call this._getChildrenMaxSize() from the allocate() vfunc of
IconGridLayout. Since the function is quite expensive, it slows the
layout process down a lot, so instead of re-calculating it on every
relayout, cache the max size of children.
This makes the average time spent in vfunc_allocate() of the iconGrid go
down from 2.3 ms to 1.6 ms.
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1713>
js/ui/iconGrid.js | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
---
diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js
index 2c71c29c10..12f1ac0251 100644
--- a/js/ui/iconGrid.js
+++ b/js/ui/iconGrid.js
@@ -369,6 +369,8 @@ var IconGridLayout = GObject.registerClass({
this._resolveOnIdleId = 0;
this._iconSizeUpdateResolveCbs = [];
+
+ this._childrenMaxSize = -1;
}
_findBestIconSize() {
@@ -414,21 +416,25 @@ var IconGridLayout = GObject.registerClass({
}
_getChildrenMaxSize() {
- let minWidth = 0;
- let minHeight = 0;
+ if (this._childrenMaxSize === -1) {
+ let minWidth = 0;
+ let minHeight = 0;
- for (const child of this._container) {
- if (!child.visible)
- continue;
+ for (const child of this._container) {
+ if (!child.visible)
+ continue;
- const [childMinHeight] = child.get_preferred_height(-1);
- const [childMinWidth] = child.get_preferred_width(-1);
+ const [childMinHeight] = child.get_preferred_height(-1);
+ const [childMinWidth] = child.get_preferred_width(-1);
- minWidth = Math.max(minWidth, childMinWidth);
- minHeight = Math.max(minHeight, childMinHeight);
+ minWidth = Math.max(minWidth, childMinWidth);
+ minHeight = Math.max(minHeight, childMinHeight);
+ }
+
+ this._childrenMaxSize = Math.max(minWidth, minHeight);
}
- return Math.max(minWidth, minHeight);
+ return this._childrenMaxSize;
}
_getVisibleChildrenForPage(pageIndex) {
@@ -445,6 +451,7 @@ var IconGridLayout = GObject.registerClass({
item.disconnect(itemData.destroyId);
item.disconnect(itemData.visibleId);
+ item.disconnect(itemData.queueRelayoutId);
this._items.delete(item);
}
@@ -557,6 +564,9 @@ var IconGridLayout = GObject.registerClass({
else if (!this.allowIncompletePages)
this._fillItemVacancies(itemData.pageIndex);
}),
+ queueRelayoutId: item.connect('queue-relayout', () => {
+ this._childrenMaxSize = -1;
+ }),
});
item.icon.setIconSize(this._iconSize);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]