Bug 283222

Summary: Poor performance of querySelectorAll() with descendant selectors (:has())
Product: WebKit Reporter: Jeff Johnson <opendarwin>
Component: CSSAssignee: Antti Koivisto <koivisto>
Status: RESOLVED FIXED    
Severity: Normal CC: karlcow, koivisto, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: BrowserCompat, InRadar
Version: Safari 18   
Hardware: Mac (Apple Silicon)   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=283220
https://bugs.webkit.org/show_bug.cgi?id=288923

Jeff Johnson
Reported 2024-11-15 18:53:56 PST
I discovered this bug while investigating another bug, Poor performance of selector div:has(img) button https://bugs.webkit.org/show_bug.cgi?id=283220 Steps to reproduce: 1. Open https://sdpc.a4l.org/search_national.php 2. Open the web inspector 3. document.querySelectorAll('foobar div:has(img) button') Expected results: The node list is returned immediately. Actual results: The node list takes about 3 seconds to return. Since document.querySelectorAll('foobar') contains no items, the rest of the selector should be irrelevant and ignored. But WebKit is still clearly calculating the 'div:has(img) button' part of the selector.
Attachments
Radar WebKit Bug Importer
Comment 1 2024-11-17 17:58:03 PST
Karl Dubost
Comment 2 2024-11-17 18:07:25 PST
var startTime = performance.now(); document.querySelectorAll('foobar div:has(img) button'); var endTime = performance.now(); console.log(`${endTime - startTime} milliseconds`) Safari: 2247 ms Firefox: 2 ms Chrome: 22 ms Safari Technology Preview 207 20621.1.4.3 Firefox Nightly 134.0a1 13424.11.7 Google Chrome Canary 133.0.6843.0 6843.0
Antti Koivisto
Comment 3 2024-11-20 05:52:03 PST
EWS
Comment 4 2024-11-21 08:19:44 PST
Committed 286908@main (cdba6f7e0a32): <https://commits.webkit.org/286908@main> Reviewed commits have been landed. Closing PR #36893 and removing active labels.
Antti Koivisto
Comment 5 2024-11-21 08:41:55 PST
*** Bug 283220 has been marked as a duplicate of this bug. ***
Note You need to log in before you can comment on or make changes to this bug.