Changeset 241113 in webkit
- Timestamp:
- Feb 6, 2019 7:13:11 PM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r241111 r241113 1 2019-02-06 Benjamin Poulain <benjamin@webkit.org> 2 3 Unreviewed, rolling out r240759 and r240944. 4 5 Some timer uses are done off the main thread, WebCore::Timer 6 cannot be used 7 8 Reverted changesets: 9 10 "<rdar://problem/47570443> Responsiveness timers are too 11 expensive for frequent events" 12 https://bugs.webkit.org/show_bug.cgi?id=194003 13 https://trac.webkit.org/changeset/240759 14 15 "Use deferrable timer to restart the Responsiveness Timer on 16 each wheel event" 17 https://bugs.webkit.org/show_bug.cgi?id=194135 18 https://trac.webkit.org/changeset/240944 19 1 20 2019-02-06 Keith Rollin <krollin@apple.com> 2 21 -
trunk/Source/WebCore/css/CSSImageGeneratorValue.cpp
r240944 r241113 57 57 const FloatSize m_size; 58 58 const Ref<GeneratedImage> m_image; 59 ResettableOneShotTimer m_evictionTimer;59 DeferrableOneShotTimer m_evictionTimer; 60 60 }; 61 61 -
trunk/Source/WebCore/html/HTMLPlugInImageElement.h
r240944 r241113 131 131 bool m_needsDocumentActivationCallbacks { false }; 132 132 RefPtr<MouseEvent> m_pendingClickEventFromSnapshot; 133 ResettableOneShotTimer m_simulatedMouseClickTimer;133 DeferrableOneShotTimer m_simulatedMouseClickTimer; 134 134 Timer m_removeSnapshotTimer; 135 135 RefPtr<Image> m_snapshotImage; -
trunk/Source/WebCore/loader/cache/CachedResource.h
r240944 r241113 312 312 ResourceResponse m_response; 313 313 314 ResettableOneShotTimer m_decodedDataDeletionTimer;314 DeferrableOneShotTimer m_decodedDataDeletionTimer; 315 315 316 316 // FIXME: Make the rest of these data members private and use functions in derived classes instead. -
trunk/Source/WebCore/platform/Timer.cpp
r240944 r241113 261 261 TimerBase::~TimerBase() 262 262 { 263 assertThreadSafety();263 ASSERT(canAccessThreadLocalDataForThread(m_thread.get())); 264 264 RELEASE_ASSERT(canAccessThreadLocalDataForThread(m_thread.get()) || shouldSuppressThreadSafetyCheck()); 265 265 stop(); … … 274 274 void TimerBase::start(Seconds nextFireInterval, Seconds repeatInterval) 275 275 { 276 assertThreadSafety();276 ASSERT(canAccessThreadLocalDataForThread(m_thread.get())); 277 277 278 278 m_repeatInterval = repeatInterval; … … 282 282 void TimerBase::stop() 283 283 { 284 assertThreadSafety();284 ASSERT(canAccessThreadLocalDataForThread(m_thread.get())); 285 285 286 286 m_repeatInterval = 0_s; … … 466 466 void TimerBase::setNextFireTime(MonotonicTime newTime) 467 467 { 468 assertThreadSafety();468 ASSERT(canAccessThreadLocalDataForThread(m_thread.get())); 469 469 RELEASE_ASSERT(canAccessThreadLocalDataForThread(m_thread.get()) || shouldSuppressThreadSafetyCheck()); 470 470 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!m_wasDeleted); … … 521 521 } 522 522 523 DeferrableOneShotTimer::DeferrableOneShotTimer(WTF::Function<void()>&& function)524 : m_function(WTFMove(function))525 {526 }527 528 DeferrableOneShotTimer::~DeferrableOneShotTimer() = default;529 530 void DeferrableOneShotTimer::startOneShot(Seconds interval)531 {532 assertThreadSafety();533 534 MonotonicTime oldNextFireTime = TimerBase::nextFireTime();535 if (!oldNextFireTime) {536 m_restartFireTime = MonotonicTime();537 TimerBase::startOneShot(interval);538 return;539 }540 541 MonotonicTime newNextFireTime = MonotonicTime::now() + interval;542 if (newNextFireTime < oldNextFireTime) {543 m_restartFireTime = MonotonicTime();544 TimerBase::setNextFireTime(newNextFireTime);545 return;546 }547 548 m_restartFireTime = newNextFireTime;549 }550 551 void DeferrableOneShotTimer::stop()552 {553 TimerBase::stop();554 }555 556 void DeferrableOneShotTimer::fired()557 {558 if (m_restartFireTime) {559 MonotonicTime now = MonotonicTime::now();560 MonotonicTime restartFireTime = m_restartFireTime;561 m_restartFireTime = MonotonicTime();562 if (now < restartFireTime) {563 TimerBase::setNextFireTime(restartFireTime);564 return;565 }566 }567 568 m_function();569 }570 571 523 } // namespace WebCore 572 524 -
trunk/Source/WebCore/platform/Timer.h
r240944 r241113 69 69 static void fireTimersInNestedEventLoop(); 70 70 71 protected:72 MonotonicTime nextFireTime() const { return m_heapItem ? m_heapItem->time : MonotonicTime { }; }73 void setNextFireTime(MonotonicTime);74 75 void assertThreadSafety()76 {77 ASSERT(canAccessThreadLocalDataForThread(m_thread.get()));78 }79 80 71 private: 81 72 virtual void fired() = 0; … … 85 76 void checkConsistency() const; 86 77 void checkHeapIndex() const; 78 79 void setNextFireTime(MonotonicTime); 87 80 88 81 bool inHeap() const { return m_heapItem && m_heapItem->isInHeap(); } … … 99 92 void heapPopMin(); 100 93 static void heapDeleteNullMin(ThreadTimerHeap&); 94 95 MonotonicTime nextFireTime() const { return m_heapItem ? m_heapItem->time : MonotonicTime { }; } 101 96 102 97 MonotonicTime m_unalignedNextFireTime; // m_nextFireTime not considering alignment interval … … 147 142 } 148 143 149 // ResettableOneShotTimer is a optimization for timers that need to be delayed frequently. 150 // 151 // Changing the deadline of a timer is not a cheap operation. When it is done frequently, it can 152 // affect performance. 153 // 154 // With ResettableOneShotTimer, calling restart() does not change the underlying timer. 155 // Instead, when the underlying timer fires, a new dealine is set for "delay" seconds. 156 // 157 // When a ResettableOneShotTimer of 5 seconds is restarted before the deadline, the total 158 // time before the function is called is 10 seconds. 159 // 160 // If a timer is unfrequently reset, or if it is usually stopped before the deadline, 161 // prefer WebCore::Timer to avoid idle wake-up. 162 class ResettableOneShotTimer : protected TimerBase { 144 class DeferrableOneShotTimer : protected TimerBase { 163 145 WTF_MAKE_FAST_ALLOCATED; 164 146 public: 165 147 template<typename TimerFiredClass> 166 ResettableOneShotTimer(TimerFiredClass& object, void (TimerFiredClass::*function)(), Seconds delay)167 : ResettableOneShotTimer(std::bind(function, &object), delay)148 DeferrableOneShotTimer(TimerFiredClass& object, void (TimerFiredClass::*function)(), Seconds delay) 149 : DeferrableOneShotTimer(std::bind(function, &object), delay) 168 150 { 169 151 } 170 152 171 ResettableOneShotTimer(WTF::Function<void()>&& function, Seconds delay)153 DeferrableOneShotTimer(WTF::Function<void ()>&& function, Seconds delay) 172 154 : m_function(WTFMove(function)) 173 155 , m_delay(delay) … … 215 197 }; 216 198 217 // DeferrableOneShotTimer is a optimization for timers that need to change the deadline frequently.218 //219 // With DeferrableOneShotTimer, if the new deadline is later than the original deadline, the timer220 // is not reset. Instead, the timer fires and schedule a new timer for the remaining time.221 //222 // DeferrableOneShotTimer supports absolute deadlines.223 // If a timer of 5 seconds is restarted after 2 seconds, the total time will be 7 seconds.224 //225 // Restarting a DeferrableOneShotTimer is more expensive than restarting a ResettableOneShotTimer.226 // If accumulating the delay is not important, prefer ResettableOneShotTimer.227 class WEBCORE_EXPORT DeferrableOneShotTimer : private TimerBase {228 WTF_MAKE_FAST_ALLOCATED;229 public:230 DeferrableOneShotTimer(WTF::Function<void()>&&);231 ~DeferrableOneShotTimer();232 233 void startOneShot(Seconds interval);234 void stop();235 236 private:237 void fired() override;238 239 WTF::Function<void()> m_function;240 MonotonicTime m_restartFireTime;241 };242 243 199 } -
trunk/Source/WebCore/platform/graphics/ca/TileController.h
r240944 r241113 208 208 209 209 Timer m_tileRevalidationTimer; 210 ResettableOneShotTimer m_tileSizeChangeTimer;210 DeferrableOneShotTimer m_tileSizeChangeTimer; 211 211 212 212 TileCoverage m_tileCoverage { CoverageForVisibleArea }; -
trunk/Source/WebCore/platform/graphics/cg/SubimageCacheWithTimer.h
r240944 r241113 95 95 HashCountedSet<CGImageRef> m_images; 96 96 SubimageCacheHashSet m_cache; 97 ResettableOneShotTimer m_timer;97 DeferrableOneShotTimer m_timer; 98 98 99 99 static SubimageCacheWithTimer& subimageCache(); -
trunk/Source/WebKit/ChangeLog
r241112 r241113 1 2019-02-06 Benjamin Poulain <benjamin@webkit.org> 2 3 Unreviewed, rolling out r240759 and r240944. 4 5 Some timer uses are done off the main thread, WebCore::Timer 6 cannot be used 7 8 Reverted changesets: 9 10 "<rdar://problem/47570443> Responsiveness timers are too 11 expensive for frequent events" 12 https://bugs.webkit.org/show_bug.cgi?id=194003 13 https://trac.webkit.org/changeset/240759 14 15 "Use deferrable timer to restart the Responsiveness Timer on 16 each wheel event" 17 https://bugs.webkit.org/show_bug.cgi?id=194135 18 https://trac.webkit.org/changeset/240944 19 1 20 2019-02-06 chris fleizach <cfleizach@apple.com> 2 21 -
trunk/Source/WebKit/NetworkProcess/watchos/NetworkProximityAssertion.h
r240944 r241113 88 88 uint64_t m_assertionCount { 0 }; 89 89 State m_state { State::Suspended }; 90 WebCore:: ResettableOneShotTimer m_releaseTimer;91 WebCore:: ResettableOneShotTimer m_suspendAfterBackgroundingTimer;90 WebCore::DeferrableOneShotTimer m_releaseTimer; 91 WebCore::DeferrableOneShotTimer m_suspendAfterBackgroundingTimer; 92 92 }; 93 93 -
trunk/Source/WebKit/UIProcess/ResponsivenessTimer.cpp
r240944 r241113 33 33 ResponsivenessTimer::ResponsivenessTimer(ResponsivenessTimer::Client& client) 34 34 : m_client(client) 35 , m_timer(std::bind(&ResponsivenessTimer::timerFired, this)) 35 , m_isResponsive(true) 36 , m_timer(RunLoop::main(), this, &ResponsivenessTimer::timerFired) 36 37 { 37 38 } 38 39 39 ResponsivenessTimer::~ResponsivenessTimer() = default; 40 ResponsivenessTimer::~ResponsivenessTimer() 41 { 42 m_timer.stop(); 43 } 40 44 41 45 void ResponsivenessTimer::invalidate() 42 46 { 43 m_waitingForTimer = false;44 m_useLazyStop = false;45 47 m_timer.stop(); 46 48 } … … 48 50 void ResponsivenessTimer::timerFired() 49 51 { 50 if (!m_waitingForTimer)51 return;52 53 m_waitingForTimer = false;54 m_useLazyStop = false;55 56 52 if (!m_isResponsive) 57 53 return; 58 54 59 55 if (!m_client.mayBecomeUnresponsive()) { 60 m_waitingForTimer = true;61 56 m_timer.startOneShot(responsivenessTimeout); 62 57 return; … … 72 67 void ResponsivenessTimer::start() 73 68 { 74 if (m_ waitingForTimer)69 if (m_timer.isActive()) 75 70 return; 76 71 77 m_waitingForTimer = true;78 m_useLazyStop = false;79 72 m_timer.startOneShot(responsivenessTimeout); 80 }81 82 void ResponsivenessTimer::startWithLazyStop()83 {84 if (!m_waitingForTimer) {85 start();86 m_useLazyStop = true;87 }88 73 } 89 74 … … 99 84 } 100 85 101 m_waitingForTimer = false; 102 103 if (m_useLazyStop) 104 m_useLazyStop = false; 105 else 106 m_timer.stop(); 86 m_timer.stop(); 107 87 } 108 88 … … 110 90 { 111 91 // Since there is no web process, we must not be waiting for it anymore. 112 m_waitingForTimer = false; 113 m_timer.stop(); 92 stop(); 114 93 } 115 94 -
trunk/Source/WebKit/UIProcess/ResponsivenessTimer.h
r240944 r241113 27 27 #define ResponsivenessTimer_h 28 28 29 #include < WebCore/Timer.h>29 #include <wtf/RunLoop.h> 30 30 31 31 namespace WebKit { … … 49 49 50 50 void start(); 51 52 // A responsiveness timer with lazy stop does not stop the underlying system timer when stopped.53 // Instead, it ignores the timeout if stop() was already called.54 //55 // This exists to reduce the rate at which we reset the timer.56 //57 // With a non lazy timer, we may set a timer and reset it soon after because the process is responsive.58 // For events, this means reseting a timer 120 times/s for a 60 Hz event source.59 // By not reseting the timer when responsive, we cut that in half to 60 timeout changes.60 void startWithLazyStop();61 62 51 void stop(); 63 52 … … 72 61 73 62 ResponsivenessTimer::Client& m_client; 74 WebCore::DeferrableOneShotTimer m_timer; 75 bool m_isResponsive { true }; 76 bool m_waitingForTimer { false }; 77 bool m_useLazyStop { false }; 63 bool m_isResponsive; 64 65 RunLoop::Timer<ResponsivenessTimer> m_timer; 78 66 }; 79 67 -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r241000 r241113 2358 2358 // Manually ping the web process to check for responsiveness since our wheel 2359 2359 // event will dispatch to a non-main thread, which always responds. 2360 m_process->isResponsive WithLazyStop();2360 m_process->isResponsive(nullptr); 2361 2361 } 2362 2362 -
trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp
r240954 r241113 1121 1121 } 1122 1122 1123 void WebProcessProxy::isResponsiveWithLazyStop()1124 {1125 if (m_isResponsive == NoOrMaybe::No)1126 return;1127 1128 responsivenessTimer().startWithLazyStop();1129 send(Messages::WebProcess::MainThreadPing(), 0);1130 }1131 1132 1123 bool WebProcessProxy::isJITEnabled() const 1133 1124 { -
trunk/Source/WebKit/UIProcess/WebProcessProxy.h
r240759 r241113 207 207 208 208 void isResponsive(WTF::Function<void(bool isWebProcessResponsive)>&&); 209 void isResponsiveWithLazyStop();210 209 void didReceiveMainThreadPing(); 211 210 void didReceiveBackgroundResponsivenessPing(); -
trunk/Source/WebKit/WebProcess/Plugins/PluginView.h
r240944 r241113 285 285 RefPtr<ShareableBitmap> m_transientPaintingSnapshot; 286 286 // This timer is used when plugin snapshotting is enabled, to capture a plugin placeholder. 287 WebCore:: ResettableOneShotTimer m_pluginSnapshotTimer;287 WebCore::DeferrableOneShotTimer m_pluginSnapshotTimer; 288 288 #if ENABLE(PRIMARY_SNAPSHOTTED_PLUGIN_HEURISTIC) || PLATFORM(COCOA) 289 289 unsigned m_countSnapshotRetries { 0 };
Note: See TracChangeset
for help on using the changeset viewer.