Bug 309699

Summary: ResizeObserver retains references to removed DOM elements without explicit unobserve() resulting in poor performance - they are GC'd in Firefox and Chrome
Product: WebKit Reporter: Paul Rhomberg <paulrhomberg01>
Component: WebCore Misc.Assignee: Nobody <webkit-unassigned>
Status: NEW    
Severity: Major CC: karlcow, nathan_solomon, rniwa, rreno, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 26   
Hardware: iPhone / iPad   
OS: iOS 26   
See Also: https://bugs.webkit.org/show_bug.cgi?id=310051
Bug Depends on: 309984, 310050    
Bug Blocks:    
Attachments:
Description Flags
Minimal reproduction
none
rendering of timelines in webinspector for multiple clicks. none

Paul Rhomberg
Reported 2026-03-11 11:54:23 PDT
Created attachment 478631 [details] Minimal reproduction Resize observers don't seem to garbage collect effectively. When observing a lot of elements and removing these without calling .unobserve() on them, performance degrades. To illustrate this issue, the provided html file does the following: 1. On button click, it creates 10,000 elements 2. It observes them all with a ResizeObserver 3. When the button is clicked again, the elements get removed and new ones get created & observed While on Chrome and Firefox, this cycle can be performed hundreds of times without slowdown, on Safari, the page starts lagging drastically after ~10-20 cycles, and each cycle takes longer and longer. This indicates that Firefox and Chrome perform some sort of garbage collection even when .unobserve() is not called, whereas Safari does not. Tested on Safari 26.3.1 on iOS, iPhone 15 Pro
Attachments
Minimal reproduction (1.09 KB, text/html)
2026-03-11 11:54 PDT, Paul Rhomberg
no flags
rendering of timelines in webinspector for multiple clicks. (148.27 KB, image/png)
2026-03-16 18:09 PDT, Karl Dubost
no flags
Radar WebKit Bug Importer
Comment 1 2026-03-15 03:56:28 PDT
Karl Dubost
Comment 2 2026-03-16 18:09:35 PDT
Created attachment 478702 [details] rendering of timelines in webinspector for multiple clicks. Thanks Paul. This is indeed happening. We can indeed see how the click event takes longer and longer to get dispatched.
Karl Dubost
Comment 3 2026-03-16 18:10:55 PDT
To note that the ResizeObserver callback is pretty constant around 0.113ms
Ryosuke Niwa
Comment 4 2026-03-17 01:09:24 PDT
https://commits.webkit.org/309376@main should have addressed this issue for most part.
Note You need to log in before you can comment on or make changes to this bug.