From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 8474C1FF15C for ; Fri, 5 Sep 2025 14:06:25 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A7C4213BA6; Fri, 5 Sep 2025 14:06:36 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Fri, 5 Sep 2025 13:52:01 +0200 Message-ID: <20250905120627.2585826-4-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 0.023 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 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 3/4] ui: resource tree: improve performance on initial update 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 insert nodes into the tree, we use 'insertBefore' of extjs' NodeInterface. When the node is inside a TreeStore, it calls 'registerNode' to handle some events and accounting. Sadly it does so not only for the inserted node, but also for the node in which is inserted too and that calls 'registerNode' again for all of its children. So inserting a large number of guests under node this way has (at least) O(n^2) calls to registerNode. To workaround this, create the first tree node structure outside the TreeStore and add it at the end. Further insertions are more likely to only come in small numbers. (Still have to look into if we can avoid that behavior there too) This improves the time spend in 'registerNode' (in my ~10000 guests test setup) from 4,081.6 ms to about 2.7ms. Signed-off-by: Dominik Csapak --- www/manager6/tree/ResourceTree.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/www/manager6/tree/ResourceTree.js b/www/manager6/tree/ResourceTree.js index 30754455..f9f711b6 100644 --- a/www/manager6/tree/ResourceTree.js +++ b/www/manager6/tree/ResourceTree.js @@ -328,10 +328,22 @@ Ext.define('PVE.tree.ResourceTree', { return node; }; + let firstUpdate = true; + let updateTree = function () { store.suspendEvents(); - let rootnode = me.store.getRootNode(); + let rootnode; + if (firstUpdate) { + rootnode = Ext.create('Ext.data.TreeModel', { + expanded: true, + id: 'root', + text: gettext('Datacenter'), + iconCls: 'fa fa-server', + }); + } else { + rootnode = me.store.getRootNode(); + } // remember selected node (and all parents) let sm = me.getSelectionModel(); let lastsel = sm.getSelection()[0]; @@ -451,6 +463,11 @@ Ext.define('PVE.tree.ResourceTree', { me.selectById(lastsel.data.id); } + if (firstUpdate) { + me.store.setRoot(rootnode); + firstUpdate = false; + } + // on first tree load set the selection from the stateful provider if (!pdata.updateCount) { rootnode.expand(); -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel