Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 64a3b99228214a6644b0146f40d94f7139e08527
      
https://github.com/WebKit/WebKit/commit/64a3b99228214a6644b0146f40d94f7139e08527
  Author: Ryosuke Niwa <[email protected]>
  Date:   2026-03-17 (Tue, 17 Mar 2026)

  Changed paths:
    M Source/WebCore/dom/ContentVisibilityDocumentState.cpp
    M Source/WebCore/dom/ContentVisibilityDocumentState.h
    M Source/WebCore/page/IntersectionObserver.cpp
    M Source/WebCore/page/IntersectionObserver.h

  Log Message:
  -----------
  IntersectionObserver can get sluggish over time
https://bugs.webkit.org/show_bug.cgi?id=310051

Reviewed by Geoffrey Garen.

This PR fixes a potential performance problem in IntersectionObserver when a 
single
IntersectionObserver is used to observe lots of elements. Since 
m_observationTargets
is a Vector and requires a linear search to find a matching entry, adding lots 
of
elements to be observed by IntersectionObserver can end up in O(n^2) behavior.

No new tests since there should be no behavioral differences other than the 
improved perf.

* Source/WebCore/dom/ContentVisibilityDocumentState.cpp:
(WebCore::ContentVisibilityDocumentState::updateRelevancyOfContentVisibilityElements
 const):
(WebCore::ContentVisibilityDocumentState::determineInitialVisibleContentVisibility
 const):
* Source/WebCore/dom/ContentVisibilityDocumentState.h:
(WebCore::ContentVisibilityDocumentState::hasObservationTargets const):
* Source/WebCore/page/IntersectionObserver.cpp:
(WebCore::IntersectionObserver::isObserving const):
(WebCore::IntersectionObserver::observe):
(WebCore::IntersectionObserver::unobserve):
(WebCore::IntersectionObserver::targetDestroyed):
(WebCore::IntersectionObserver::removeAllTargets):
(WebCore::IntersectionObserver::updateObservations):
(WebCore::IntersectionObserver::isReachableFromOpaqueRoots const):
* Source/WebCore/page/IntersectionObserver.h:
(WebCore::IntersectionObserver::hasObservationTargets const):

Canonical link: https://commits.webkit.org/309387@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to