Rewrite counters implementation to no cache approach
This CL removes the old counters implementation that was building
and maintaining a cache of counters (building counters tree).
The removal is due to the following reasons:
- It didn't support Shadow DOM and there was no way to fix it;
- It didn't work correctly with style containment and there was
no way to fix it; - It was slow and complicated;
- It was wrong in many cases.
The new approach doesn't build any cache of counters, instead it
visits every element on the very first AttachLayoutTree for the
document and gathers on the fly all the information it needs to
correctly calculate the counters values. It means that we don't
have any overhead due to some additional traversals to build the
counters cache on the first go.
So, all the pages with static (created once and not changed) counters
would render faster.
If there are some counter changes after the first AttachLayoutTree,
we would remember it and then recalculate all counters by doing a full
tree traversal, calculating correct counters values and only update
LayoutCounters created with counter() and counters() functions.
Performance tests held on 300'000 elements with various layouts and
various style updates/element insertions/removals show that doing
such full tree traversal for counter updates doesn't introduce any
noticeable overhead with other browsers (should be noticed that old
implementation could also do full tree traversal in some cases).
For pages with static counters performance for initial document render
is improved around 10 times against the old implementation.
Bug: 990657
Change-Id: I292d3749ad0bf480e88d815e9dbecebe9edc7067
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5483870
Commit-Queue: Daniil Sakhapov sakhapov@chromium.org
Reviewed-by: Rune Lillesveen futhark@chromium.org
Cr-Commit-Position: refs/heads/main@{#1298057}