Repository navigation
🐛 fix(cssom): keep computed_style linear in any call order - #2181
Conversation
computed_style() cascaded every ancestor of an element whose parent was not one of the two cached maps, so its cost grew with depth times calls. The cache now keeps the chain of the last element asked about, plus one checkpoint per sixteen levels of chains it has walked, keyed by node, so any access order cascades a bounded number of levels per call. Computed values borrow stylesheet, initial and inline style text the cache holds instead of copying it per element. Fixes tox-dev#1718
Merging this PR will regress 3 benchmarks2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance ChangesTip Investigate this regression by commenting Comparing Footnotes
|
Calling
computed_style()on an element of a deeply nested page restyled every ancestor from the root on each call, so styling every element of such a page cost time that grew with the square of the document for XML trees. 🎨 Once this merges, each call restyles a bounded number of elements, whatever order the calls come in. Fixes #1718.The style cache now keeps the computed values along the path of the last element asked about, and a few checkpoints further up. A call climbs only to the nearest ancestor the cache already holds, so a walk in document order styles each element once, and a call that jumps between branches restyles at most a few dozen levels above the nearest checkpoint. The computed values point at text the cache already keeps, such as the stylesheet buffers and each element's parsed
styleattribute, instead of copying it at every level.Behavior changes