fardin-developer commented on PR #34233:
URL: https://github.com/apache/superset/pull/34233#issuecomment-3107914851
## Performance Enhancements
- **WeakMap-based style caching**
A WeakMap<Element, CSSStyleDeclaration> is employed to cache the results of
getComputedStyle, eliminating redundant computations for elements that have
already been processed. This cache provides efficient O(1) lookups and
automatically clears entries when elements are removed from the DOM, reducing
traversal overhead.
- **Breadth-First Search (BFS) DOM Traversal**
The recursive style-copying logic has been replaced with an iterative
Breadth-First Search (BFS) approach using an explicit queue (Array<[Element,
Element]>). This change offers several benefits:
1. Prevents stack overflow in deeply nested DOM structures.
2. Reduces per-node function call overhead by eliminating recursion.
3. Ensures consistent and complete traversal across large or complex
trees.
- **Critical Style Filtering Using Set**
To optimize cloning further, only a defined set of critical CSS properties
is copied using a Set for fast membership checks. This selective copying
reduces the size of the cloned DOM and improves rendering performance by
excluding unnecessary styles such as transitions and browser defaults.
## See the difference between the previous and optimized approach:
[<img width="1200" height="601" alt="banner"
src="https://github.com/user-attachments/assets/0767896f-7585-475d-88f9-48dc7fe9566b"
/>](https://drive.google.com/file/d/1uFUvm8OQb35Fm9mKJvHR81Crdf6X3mgu/view?usp=sharing)
Ckick the banner to watch the video
#
[Link](https://drive.google.com/file/d/1uFUvm8OQb35Fm9mKJvHR81Crdf6X3mgu/view?usp=sharing)
: Click the banner or link to Watch the Video
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]