Review main Abandoned

88227[TASK] Reduce number of event-listeners for tree-component

Ayke Halder CR 0 V 0 Normal +140 −62 updated 11/10/26, 11:02

Commit message

This moves always implemented event-listeners to the parent container
of the tree-component.
The tree-nodes do not implement these event-listeners anymore.

On scrolling or navigating the tree, tree-nodes are constantly added
and removed.

Before each tree-node implemented around 12 event-listeners resulting in
a total of round about 300 event-listeners.
Also a big number of event-listeners was constantly created
and removed, which slowed down the creation of tree-nodes.
Also this resulted in unused memory and garbage collection (GC).

Review

  • Code review CR 0
  • Verified V 0
    • core-ci +1 CI

Issues 1

Files 6

Review log 1316

  1. Ayke Halder uploaded patch set 1 02/15/25, 12:29

  2. Ayke Halder commented on patch set 1 02/15/25, 12:33

    ### Event-listerners in page-module All the event listeners inside shadow DOM might not be included here. #### Before: ```js { "click": 88, "dblclick": 64, "dragstart": 39, "dragover": 32, "dragleave": 32, "dragend": 32, "drop": 32, "focusin": 32, "focusout": 32, "contextmenu": 32, "t3-topbar-update": 6, "keydown": 3, "touchstart": 2, "submit": 1, "reset": 1, "shown.bs.collapse": 1, "input": 1, "tree:initialized": 1, "typo3:tree:node-selected": 1, "typo3:tree:node-context": 1, "typo3:tree:nodes-prepared": 1, "scroll": 1, "mouseover": 1, "mouseout": 1, "mousedown": 1, "typo3-module-load": 1, "typo3-module-loaded": 1, "typo3-iframe-load": 1, "typo3-iframe-loaded": 1, "load": 1 } ``` #### With this patch: ```js { "click": 22, "dblclick": 1, "dragstart": 8, "dragover": 1, "dragleave": 1, "dragend": 1, "drop": 1, "focusin": 1, "focusout": 1, "contextmenu": 1, "t3-topbar-update": 6, "keydown": 3, "touchstart": 2, "submit": 1, "reset": 1, "shown.bs.collapse": 1, "input": 1, "tree:initialized": 1, "typo3:tree:node-selected": 1, "typo3:tree:node-context": 1, "typo3:tree:nodes-prepared": 1, "scroll": 1, "mouseover": 1, "mouseout": 1, "mousedown": 1, "typo3-module-load": 1, "typo3-module-loaded": 1, "typo3-iframe-load": 1, "typo3-iframe-loaded": 1, "load": 1 } ```
  3. core-ci voted on patch set 1 V +1 02/15/25, 12:35 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/74179

  4. Ayke Halder uploaded patch set 2 V +1 02/15/25, 12:50

  5. core-ci voted on patch set 2 V +1 02/15/25, 12:57 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/74180

  6. Ayke Halder rebased onto patch set 3 V +1 02/18/25, 11:11

  7. core-ci voted on patch set 3 V +1 02/18/25, 11:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/74305

  8. Benni Mack commented on patch set 3 03/28/25, 11:33

    Is this an actual issue that fixes a real bug where something is broken, or is this an optimization mainly based on memory consumption / GC which is not perceivable for an editor?
  9. Ayke Halder commented on patch set 3 03/28/25, 14:55

    Reply

    About those event-listeners here: they are only part of the problem - and are actually neglectable. On a CPU with low clock speed opening big sub-trees takes around 140 ms (sub-tree already cached, no http-request). Ideally this should be below 100 ms (= perceived instantaneous). Firefox performance reports show: > **140 ms Jank - event processing delay** > Jank markers show when the main event loop of a thread has been busy. It is a good indicator that there may be some kind of performance problem worth investigating. ---- Looking deep into the tree rendering there are two main points which cause delays: ### 1) Tree has a huge number of HTML Elements and SVG-Images Changes of tree nodes trigger lots of native browser function-calls: This is a performance issue of LitElement. ### 2) Object-storage of the tree-nodes is implemented as array The tree-nodes don't know their parents, resulting in complex calculations to find the parent each time when there is a tree change. On tree-rendering the function `getParentNode` calls `getNodeByTreeIdentifier` which calls `this.nodes.find(…)` inside an iterative loop. Time used to find parents is around 30 ms total on opening/closing any sub-tree. I think Big-O complexity of the calculation is **O(n^(m²))** with **n**: number of visible nodes (~20-30) and **m**: depth of tree (3-4). By storing each child-node with a reference to its parent node, the time of searching for parents can be reduced from **O(n^(m²))** [30 ms] to **O(n)** [2-3 ms].
  10. Ayke Halder commented on patch set 3 10/28/25, 14:53

  11. Ayke Halder abandoned the change 10/28/25, 14:53

  12. Ayke Halder restored the change 10/28/25, 15:04

  13. Benni Mack wrote 04/21/26, 14:57

    Removed cc Benni Mack.
  14. Benni Mack commented on patch set 3 11/10/26, 10:41

    the affected issue 106182 is closed... are you going to continue here?
  15. Ayke Halder commented on patch set 3 11/10/26, 11:01

    Reply

    Closing for now. I Have to get direct feedback from @ben@bnf.dev on this patch and the related patches - see relation chain.
  16. Ayke Halder abandoned the change 11/10/26, 11:02

    Needs another attempt for completion.