all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager 3/4] ui: resource tree: improve performance on initial update
Date: Fri,  5 Sep 2025 13:52:01 +0200	[thread overview]
Message-ID: <20250905120627.2585826-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250905120627.2585826-1-d.csapak@proxmox.com>

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 <d.csapak@proxmox.com>
---
 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


  parent reply	other threads:[~2025-09-05 12:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05 11:51 [pve-devel] [PATCH manager 0/4] gui/api performance improvements Dominik Csapak
2025-09-05 11:51 ` [pve-devel] [PATCH manager 1/4] API2Tools: rrd: remove O(n^2) lookup for keys Dominik Csapak
2025-09-05 13:49   ` Aaron Lauterer
2025-09-05 13:53     ` Dominik Csapak
2025-09-05 13:58       ` Aaron Lauterer
2025-09-05 13:57   ` Daniel Kral
2025-09-05 11:52 ` [pve-devel] [PATCH manager 2/4] ui: fix O(n^2) calculations when loading /cluster/resources Dominik Csapak
2025-09-05 11:52 ` Dominik Csapak [this message]
2025-09-05 11:52 ` [pve-devel] [PATCH manager 4/4] ui: resource tree: fix change detection Dominik Csapak
2025-09-05 17:40 ` [pve-devel] applied: [PATCH manager 0/4] gui/api performance improvements Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250905120627.2585826-4-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal