Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 7369e2faf2790fb25ef0736579f8eb1d0b9c6d2d
      
https://github.com/WebKit/WebKit/commit/7369e2faf2790fb25ef0736579f8eb1d0b9c6d2d
  Author: Simon Fraser <[email protected]>
  Date:   2026-07-25 (Sat, 25 Jul 2026)

  Changed paths:
    M 
Source/WebKit/UIProcess/RemoteLayerTree/mac/RemoteLayerTreeDrawingAreaProxyMac.h
    M 
Source/WebKit/UIProcess/RemoteLayerTree/mac/RemoteLayerTreeDrawingAreaProxyMac.mm

  Log Message:
  -----------
  Safari main thread can block under 
RemoteLayerTreeEventDispatcher::mainThreadDisplayDidRefresh()
https://bugs.webkit.org/show_bug.cgi?id=320209
rdar://182918397

Reviewed by Tim Horton.

`RemoteLayerTreeDisplayLinkClient::displayLinkFired()` is called off the main 
thread from
a CVDisplayLink callback, and does a `RunLoop::mainSingleton().dispatch()`. If 
the main
thread is busy for some reason (either CPU bound, or perhaps in some scenarios 
involving
machine sleep or certain window configurations), then the main thread 
dispatches pile up.
When the main thread finally wakes up, it may have a huge queue of callbacks to 
process.
My my testing, things like window resize and printing could result in queued 
callbacks.

As noted in my earlier fix in this area (313360@main), each call to the drawing 
area's
`didRefreshDisplay()` can block for about 4ms because it's trying to sync with 
the
scrolling thread, so this pile of callbacks can take a long time to process, 
resulting
in user-perceived hangs.

Fix by coalescing the main thread dispatches via an atomic timestamp on 
`RemoteLayerTreeDisplayLinkClient`.
In order to clear this inside the callback, make 
`RemoteLayerTreeDisplayLinkClient`
thread-safe refcounted with a create function.

Because getting stuck never calling `didRefreshDisplay()` on a drawing area 
would be
catastrophic, be paranoid and call it anyway if it's been over 500ms since the 
previous
successful call, with some release logging.

* 
Source/WebKit/UIProcess/RemoteLayerTree/mac/RemoteLayerTreeDrawingAreaProxyMac.h:
* 
Source/WebKit/UIProcess/RemoteLayerTree/mac/RemoteLayerTreeDrawingAreaProxyMac.mm:
(WebKit::RemoteLayerTreeDisplayLinkClient::displayLinkFired):
(WebKit::RemoteLayerTreeDrawingAreaProxyMac::RemoteLayerTreeDrawingAreaProxyMac):

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



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

Reply via email to