Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 98bcca039303cd9c62caf7e7d4543e6c2e6794e0
      
https://github.com/WebKit/WebKit/commit/98bcca039303cd9c62caf7e7d4543e6c2e6794e0
  Author: Ben Nham <[email protected]>
  Date:   2026-10-14 (Wed, 14 Oct 2026)

  Changed paths:
    M Source/WebCore/page/EventHandler.cpp
    M Source/WebCore/page/EventHandler.h
    M Source/WebCore/page/scrolling/ScrollLatchingController.cpp
    M Source/WebCore/page/scrolling/ScrollLatchingController.h
    M 
Tools/TestWebKitAPI/Tests/WebKit/WKWebView/mac/ScrollingCoordinatorTests.mm

  Log Message:
  -----------
  Avoid hit testing wheel events that continue a latched gesture
https://bugs.webkit.org/show_bug.cgi?id=327046
rdar://problem/189656485

Reviewed by Simon Fraser.

EventHandler::handleWheelEventInternal hit tests every wheel event. For events 
that continue a
latched gesture (e.g. a Changed or Ended event, which is most of the events 
during a scroll),
ScrollLatchingController replaces the hit test's results with the latched 
state. So for most of the
events in a scroll gesture, the hit test is wasted work. The hit test also 
forces a layout, which is
also extra work if the page changes layout again before the next rendering 
update.

Optimize this by using the latched state without a hit test when it's safe, 
i.e. when the event
continues a latched gesture with a latched scroller and doesn't scroll on the 
main thread
(as scrolling on the main thread requires up-to-date layout).

On the macOS power benchmark, this reduces WebContent CPU usage by ~3%.

Test: 
Tools/TestWebKitAPI/Tests/WebKit/WKWebView/mac/ScrollingCoordinatorTests.mm

* Source/WebCore/page/EventHandler.cpp:
(WebCore::EventHandler::fetchLatchedWheelEventTarget):
(WebCore::EventHandler::handleWheelEventInternal):
* Source/WebCore/page/EventHandler.h:
* Source/WebCore/page/scrolling/ScrollLatchingController.cpp:
(WebCore::ScrollLatchingController::fetchLatchedStateIfIndependentOfHitTest 
const):
* Source/WebCore/page/scrolling/ScrollLatchingController.h:
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/mac/ScrollingCoordinatorTests.mm:
(TestWebKitAPI::waitForCondition):
(TestWebKitAPI::TEST(ScrollingCoordinatorTests, 
LatchedWheelGestureIgnoresElementCoveringPointer)):

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



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

Reply via email to