Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: ecd009129377e8b137d771313e82be843dadaa59
      
https://github.com/WebKit/WebKit/commit/ecd009129377e8b137d771313e82be843dadaa59
  Author: Ryosuke Niwa <[email protected]>
  Date:   2024-03-31 (Sun, 31 Mar 2024)

  Changed paths:
    M 
LayoutTests/requestidlecallback/requestidlecallback-in-page-cache-with-pending-task.html
    A 
LayoutTests/requestidlecallback/requestidlecallback-is-called-even-when-event-loop-is-busy-expected.txt
    A 
LayoutTests/requestidlecallback/requestidlecallback-is-called-even-when-event-loop-is-busy.html
    A 
LayoutTests/requestidlecallback/requestidlecallback-is-called-when-idle-expected.txt
    A 
LayoutTests/requestidlecallback/requestidlecallback-is-called-when-idle.html
    M Source/WebCore/dom/Document.cpp
    M Source/WebCore/dom/Document.h
    M Source/WebCore/dom/IdleCallbackController.cpp
    M Source/WebCore/dom/Microtasks.cpp
    M Source/WebCore/dom/Microtasks.h
    M Source/WebCore/dom/WindowEventLoop.cpp
    M Source/WebCore/dom/WindowEventLoop.h
    M Source/WebCore/page/OpportunisticTaskScheduler.h

  Log Message:
  -----------
  airbnb.com: When trying to select days for checkin checkout, the date widget 
is empty
https://bugs.webkit.org/show_bug.cgi?id=268058

Reviewed by Chris Dumez and Wenson Hsieh.

This PR fixes a few bugs that caused idle callbacks to sometimes not get 
invoked.

1. Check for the existence of microtasks in shouldEndIdlePeriod and 
didReachTimeToRun were not taking
into account that there could be suspended microtasks (e.g. microtasks for a 
document in page cache).
Fixed this bug by introducing 
MicrotaskQueue::hasMicrotasksForFullyActiveDocument which checks for an
existence of a microtask for a fully active document.

2. When the event loop is sufficiently busy such that there is no idle period 
of at least 4ms,
opportunisticallyRunIdleCallbacks and didReachTimeToRun would perpetually defer 
idle callbacks.
Fixed this bug by decaying (shortening) the expected idle callback duration in 
each iteration using
exponential moving average with the weight of 50%. This will eventually shorten 
the expected idle
callback duration enough to start the idle period even when the event loop is 
constantly scheduling
timers and rAF callbacks.

3. opportunisticallyRunIdleCallbacks and didReachTimeToRun can sometimes exit 
without processing
pending idle callbacks and never schedule itself again when the initial check 
for idleness had failed.
Fixed this bug by always scheduling the event loop to run via 
scheduleToRunIfNeeded and in addition to
signaling OpportunisticTaskScheduler in 
IdleCallbackController::queueIdleCallback. This PR also moves
the code to signal OpportunisticTaskScheduler from Document to WindowEventLoop.

* 
LayoutTests/requestidlecallback/requestidlecallback-in-page-cache-with-pending-task.html:
 Added web
animation so that a microtask to stop the animation is queued as the document 
moves into the page cache.
* 
LayoutTests/requestidlecallback/requestidlecallback-is-called-even-when-event-loop-is-busy-expected.txt:
 Added.
* 
LayoutTests/requestidlecallback/requestidlecallback-is-called-even-when-event-loop-is-busy.html:
 Added.
* 
LayoutTests/requestidlecallback/requestidlecallback-is-called-when-idle-expected.txt:
 Added.
* LayoutTests/requestidlecallback/requestidlecallback-is-called-when-idle.html: 
Added.
* Source/WebCore/dom/Document.cpp:
(WebCore::Document::protectedWindowEventLoop): Added.
(WebCore::Document::requestIdleCallback):
* Source/WebCore/dom/Document.h:
* Source/WebCore/dom/IdleCallbackController.cpp:
(WebCore::IdleCallbackController::queueIdleCallback):
* Source/WebCore/dom/Microtasks.cpp:
(WebCore::MicrotaskQueue::hasMicrotasksForFullyActiveDocument const): Added.
* Source/WebCore/dom/Microtasks.h:
* Source/WebCore/dom/WindowEventLoop.cpp:
(WebCore::WindowEventLoop::scheduleIdlePeriod): Signal 
OpportunisticTaskScheduler and schedule the event
loop to run again.
(WebCore::WindowEventLoop::opportunisticallyRunIdleCallbacks):
(WebCore::WindowEventLoop::shouldEndIdlePeriod):
(WebCore::WindowEventLoop::didReachTimeToRun): Call shouldEndIdlePeriod instead 
of duplicating the code.
* Source/WebCore/dom/WindowEventLoop.h:
* Source/WebCore/page/OpportunisticTaskScheduler.h:

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to