Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: c95ca299507a31b9485268ec00dfd64ce6b6353f
https://github.com/WebKit/WebKit/commit/c95ca299507a31b9485268ec00dfd64ce6b6353f
Author: Nipun Shukla <[email protected]>
Date: 2026-06-18 (Thu, 18 Jun 2026)
Changed paths:
M Source/WebCore/dom/Node.cpp
Log Message:
-----------
Fix performance cliff in PerformanceTests/CSS/StyleSheetInsert.html
https://bugs.webkit.org/show_bug.cgi?id=316840
rdar://179279796
Reviewed by Antti Koivisto.
Previously, isSiblingSubsequent() determined sibling order by walking
forward-only from the first node to the end of the child list, so the
cost scaled with the number of following siblings rather than the distance
between the two nodes. Inserting a <style> at the front of a large element
list -- as StyleSheetInsert.html does 50 times into a 10,001-element document
-- made each comparison O(n) and ran the test over 1000x slower than Chromium.
This changes behavior to search outward from the first node in both directions
at once, returning as soon as either reaches the second node. The cost is now
proportional to the distance between the two siblings, and the result is
unchanged.
Additionally, short-circuit the sibling-ordering scan in isSiblingSubsequent()
with
O(1) checks that resolve the comparison immediately when either node is the
first or
last child, avoiding a linear walk in boundary cases.
StyleSheetInsert.html is progressed from an average of 83.5 ms to 0.19 ms
averaged
across 20 runs. This change causes no user-apparent functional difference so
correctness will be verified with existing tests.
* Source/WebCore/dom/Node.cpp:
(WebCore::isSiblingSubsequent):
Canonical link: https://commits.webkit.org/315494@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications