Created attachment 467500 [details] HTML file that illustrates the performance degradation and rise in memory. Press the Test button and watch the process size grow. In our web application we've noticed a significant rise in process memory after showing and hiding DOM UI subtrees made up of a large number of custom elements that utilize style tags that refer to CSS custom properties. In Safari 16.5 as well as WebKit 267464@main, the attached test case can start out consuming about 44 MB but after a few iterations, the process size can jump up to 1.6 GB or more. A GC or something will eventually kick in and the process size will drop back down to the 100 MB range, but then the process size will slowly climb back up again to the 1 GB range. As memory grows, performance also degrades significantly to the point where rendering stops happening, and you'll see occasional flashes of the content being shown.
Created attachment 467501 [details] Video demonstrating what we see when running the test case. Attaching a quick video that shows what we see when running the test case.
<rdar://problem/114731415>
The slowness here is caused by bug 262891.
The memory growth appears to be a separate issue from that. In trunk it can go over 1GB but at some point it drops down to ~150MB range. I suspect this behavior is GC related.
The reason for memory growth is that the style resolver sharing cache in Style::Scope has unlimited size and the test case keeps adding more items there. Low memory handler clears the cache causing memory use to eventually drop.
Pull request: https://github.com/WebKit/WebKit/pull/18889
Committed 269142@main (b3c5d420be05): <https://commits.webkit.org/269142@main> Reviewed commits have been landed. Closing PR #18889 and removing active labels.