From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 79B221FF15C for ; Fri, 5 Sep 2025 14:06:48 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0800D13D5C; Fri, 5 Sep 2025 14:07:05 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Fri, 5 Sep 2025 13:52:00 +0200 Message-ID: <20250905120627.2585826-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250905120627.2585826-1-d.csapak@proxmox.com> References: <20250905120627.2585826-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -1.027 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_MAILER 2 Automated Mailer Tag Left in Email POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH manager 2/4] ui: fix O(n^2) calculations when loading /cluster/resources X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" when we fetch the cluster resources, the ui calculates some fields for each resource, such as 'hostmem_usage'. This requires the maxmem attribute from the host which we have to look up in the resource store. Since the data is not sorted in the store itself, extjs linearly goes through the records to make the lookup when we use 'findExact'. So instead of using findExact for every guest (which iterates the whole resource store again), use a 'nodeCache' there and clear it out before we load the new data. This reduces the total time used for 'cacluate_hostmem_usage' in my test setup (~10000 non-running vms) from 4,408.2 ms to 12.4 ms. (Measured with the `Performance` tab in Chromium) Signed-off-by: Dominik Csapak --- www/manager6/Utils.js | 12 ++++-------- www/manager6/data/ResourceStore.js | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js index 57a818f6..c48ee0b2 100644 --- a/www/manager6/Utils.js +++ b/www/manager6/Utils.js @@ -1070,8 +1070,7 @@ Ext.define('PVE.Utils', { return -1; } - var index = PVE.data.ResourceStore.findExact('id', 'node/' + data.node); - var node = PVE.data.ResourceStore.getAt(index); + let node = PVE.data.ResourceStore.getNodeById(data.node); if (!Ext.isDefined(node) || node === null) { return -1; } @@ -1093,8 +1092,7 @@ Ext.define('PVE.Utils', { return ''; } - var index = PVE.data.ResourceStore.findExact('id', 'node/' + record.data.node); - var node = PVE.data.ResourceStore.getAt(index); + let node = PVE.data.ResourceStore.getNodeById(record.data.node); if (!Ext.isDefined(node) || node === null) { return ''; } @@ -1148,8 +1146,7 @@ Ext.define('PVE.Utils', { return -1; } - var index = PVE.data.ResourceStore.findExact('id', 'node/' + data.node); - var node = PVE.data.ResourceStore.getAt(index); + let node = PVE.data.ResourceStore.getNodeById(data.node); if (!Ext.isDefined(node) || node === null) { return -1; @@ -1199,8 +1196,7 @@ Ext.define('PVE.Utils', { return ''; } - var index = PVE.data.ResourceStore.findExact('id', 'node/' + record.data.node); - var node = PVE.data.ResourceStore.getAt(index); + let node = PVE.data.ResourceStore.getNodeById(record.data.node); var maxmem = node.data.maxmem || 0; if (record.data.mem > 1) { diff --git a/www/manager6/data/ResourceStore.js b/www/manager6/data/ResourceStore.js index d1f3fb63..bf740129 100644 --- a/www/manager6/data/ResourceStore.js +++ b/www/manager6/data/ResourceStore.js @@ -2,6 +2,8 @@ Ext.define('PVE.data.ResourceStore', { extend: 'Proxmox.data.UpdateStore', singleton: true, + nodeCache: {}, + findVMID: function (vmid) { let me = this; return me.findExact('vmid', parseInt(vmid, 10)) >= 0; @@ -21,6 +23,22 @@ Ext.define('PVE.data.ResourceStore', { return nodes; }, + getNodeById: function (id) { + let me = this; + + if (!me.nodeCache[id]) { + let idx = me.findExact('id', `node/${id}`); + me.nodeCache[id] = me.getAt(idx); + } + + return me.nodeCache[id]; + }, + + clearCache: function () { + let me = this; + me.nodeCache = {}; + }, + storageIsShared: function (storage_path) { let me = this; @@ -372,5 +390,7 @@ Ext.define('PVE.data.ResourceStore', { }); me.callParent([config]); + + me.on('beforeload', me.clearCache, me); }, }); -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel