NEW 92438
Teach Timer how to handle timer priorities.
https://bugs.webkit.org/show_bug.cgi?id=92438
Summary Teach Timer how to handle timer priorities.
Kwang Yul Seo
Reported 2012-07-26 16:43:58 PDT
Currently, HTMLParserScheduler checks if the layout timer is active (a layout is scheduled) and defer its timer. This policy is hardcoded in the parser code. We can handle this automatically by teaching Timer how to handle timer priorities. Added an optional TimerPriority argument to the Timer constructor. When fired, the timer checks if there is other active timer with higher priority. If there is one, the timer defers itself automatically. This is slightly more efficient because the timer can query the other timer's nextFireInterval and defers itself by that amount instead of polling with 0 interval. Priority value can be one of TimerPriority enum values: TimerPriorityNone, TimerPriorityLow, TimerPriorityMedium and TimerPriorityHigh. TimerPriorityNone is special and ignores the priority. Because TimerPriorityNone is the default value, existing Timer code paths are not affected by this change. Gave the layout timer higher priority than the parser scheduler timer. Then the parser scheduler timer is defered until there is no active layout timer.
Attachments
Patch (9.77 KB, patch)
2012-07-26 16:49 PDT, Kwang Yul Seo
no flags
Kwang Yul Seo
Comment 1 2012-07-26 16:49:14 PDT
Eric Seidel (no email)
Comment 2 2012-07-26 17:22:36 PDT
I'm skeptical that we need this complexity.
Build Bot
Comment 3 2012-07-26 18:55:42 PDT
Kwang Yul Seo
Comment 4 2012-07-26 19:09:03 PDT
(In reply to comment #2) > I'm skeptical that we need this complexity. Yes, this patch became more complex than expected. Let's listen to other opinions before I work on fixing mac build.
Sam Weinig
Comment 5 2012-07-26 23:48:51 PDT
What is the benefit of this patch? What else will these priorities be used for. The added complexity and increased size of Timer objects seems questionable.
Kwang Yul Seo
Comment 6 2012-07-27 00:28:20 PDT
(In reply to comment #5) > What is the benefit of this patch? What else will these priorities be used for. The added complexity and increased size of Timer objects seems questionable. Because WebKit is mostly single-threaded, timers are used as a task scheduler. When the shared timer is fired, there are usually many competing timers that need to be fired. Because there is no concept of timer priority in WebKit timers, a random timer among candidates is chosen and fired. The benefit of timer priority is quite similar to process priority of operating systems. This patch shows one such example. When both the layout timer and the parser scheduler timer are active, we need to pick and fire the layout timer because the layout timer has higher priority. Currently, the parser scheduler timer manually yields when the layout timer is active. This reminds me of cooperative multi-threading used in old days. I haven't surveyed all the timers in WebKit, but I guess we can improve responsiveness by giving higher priority to user events processing or repaint tasks. I know this sounds quite hypothetical, but I don't have hard evidence supporting this theory :( Thanks for the comments. I won't be sad even if you give me r-.
Sam Weinig
Comment 7 2012-07-27 09:26:43 PDT
(In reply to comment #6) > (In reply to comment #5) > > What is the benefit of this patch? What else will these priorities be used for. The added complexity and increased size of Timer objects seems questionable. > > Because WebKit is mostly single-threaded, timers are used as a task scheduler. When the shared timer is fired, there are usually many competing timers that need to be fired. Because there is no concept of timer priority in WebKit timers, a random timer among candidates is chosen and fired. > > The benefit of timer priority is quite similar to process priority of operating systems. This patch shows one such example. When both the layout timer and the parser scheduler timer are active, we need to pick and fire the layout timer because the layout timer has higher priority. Currently, the parser scheduler timer manually yields when the layout timer is active. This reminds me of cooperative multi-threading used in old days. > > I haven't surveyed all the timers in WebKit, but I guess we can improve responsiveness by giving higher priority to user events processing or repaint tasks. I know this sounds quite hypothetical, but I don't have hard evidence supporting this theory :( > > Thanks for the comments. I won't be sad even if you give me r-. I certainly like the idea of prioritizing user events, but I would need to see data indicating it sped something up before we went ahead and did this.
Kwang Yul Seo
Comment 8 2012-07-27 22:13:55 PDT
(In reply to comment #7) > I certainly like the idea of prioritizing user events, but I would need to see data indicating it sped something up before we went ahead and did this. Okay. I will see if I can show you the benefits with real data. Thanks.
Eric Seidel (no email)
Comment 9 2012-08-07 15:55:05 PDT
Comment on attachment 154789 [details] Patch Removing this from the review queue for now.
Note You need to log in before you can comment on or make changes to this bug.