WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
142752
[Mac][iOS] setSharedTimerFireInterval() / stopSharedTimer() are expensive
https://bugs.webkit.org/show_bug.cgi?id=142752
Summary
[Mac][iOS] setSharedTimerFireInterval() / stopSharedTimer() are expensive
Chris Dumez
Reported
2015-03-16 15:09:40 PDT
setSharedTimerFireInterval() / stopSharedTimer() are expensive on Mac and iOS on pages using a lot of timers. For example, on bing.com, ~15.4% of the CPU time is spent in setSharedTimerFireInterval() and ~14.7% of the CPU time is spent in stopSharedTimer(). The expensive calls are CFRunLoopAddTimer (11.4%), CFRunLoopTimerInvalidate (14.1%), CFRunLoopTimerCreate (3.3%). The issue is that we keep creating, adding to run loop modes, and then destroying the sharedTimer for each firing event. This is very expensive. In such case, the CFRunLoopTimerRef documentation advises to """ ... create a repeating timer with an initial firing time in the distant future (or the initial firing time) and a very large repeat interval—on the order of decades or more—and add it to all the necessary run loop modes. Then, when you know when the timer should fire next, you reset the firing time with CFRunLoopTimerSetNextFireDate, perhaps from the timer’s own callback function. This technique effectively produces a reusable, asynchronous timer. """ [1]. Doing so greatly decreases CPU using in setSharedTimerFireInterval() (15.4% -> 4.6%) and stopSharedTimer() (14.6% -> 8.6%). [1]
https://developer.apple.com/library/prerelease/ios/documentation/CoreFoundation/Reference/CFRunLoopTimerRef/index.html#//apple_ref/c/func/CFRunLoopTimerSetNextFireDate
Radar: <
rdar://problem/20176731
>.
Attachments
Patch
(6.32 KB, patch)
2015-03-16 15:19 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Archive of layout-test-results from ews100 for mac-mavericks
(652.12 KB, application/zip)
2015-03-16 15:42 PDT
,
Build Bot
no flags
Details
Archive of layout-test-results from ews104 for mac-mavericks-wk2
(632.60 KB, application/zip)
2015-03-16 15:44 PDT
,
Build Bot
no flags
Details
Patch
(7.08 KB, patch)
2015-03-16 17:27 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Archive of layout-test-results from ews100 for mac-mavericks
(523.62 KB, application/zip)
2015-03-16 18:14 PDT
,
Build Bot
no flags
Details
Archive of layout-test-results from ews104 for mac-mavericks-wk2
(573.52 KB, application/zip)
2015-03-16 18:22 PDT
,
Build Bot
no flags
Details
Patch
(10.29 KB, patch)
2015-03-16 20:33 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(10.38 KB, patch)
2015-03-16 20:52 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(10.41 KB, patch)
2015-03-16 21:00 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(10.88 KB, patch)
2015-03-16 21:03 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Archive of layout-test-results from ews101 for mac-mavericks
(524.13 KB, application/zip)
2015-03-16 21:52 PDT
,
Build Bot
no flags
Details
Patch
(11.35 KB, patch)
2015-03-16 22:15 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(11.71 KB, patch)
2015-03-16 22:29 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(11.75 KB, patch)
2015-03-16 22:45 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(12.22 KB, patch)
2015-03-16 22:49 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(32.35 KB, patch)
2015-03-17 11:39 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Archive of layout-test-results from ews102 for mac-mavericks
(532.73 KB, application/zip)
2015-03-17 12:29 PDT
,
Build Bot
no flags
Details
Patch
(32.38 KB, patch)
2015-03-17 13:28 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(38.24 KB, patch)
2015-03-17 13:54 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(38.26 KB, patch)
2015-03-17 14:31 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Show Obsolete
(19)
View All
Add attachment
proposed patch, testcase, etc.
Chris Dumez
Comment 1
2015-03-16 15:19:34 PDT
Created
attachment 248753
[details]
Patch
Build Bot
Comment 2
2015-03-16 15:41:56 PDT
Comment on
attachment 248753
[details]
Patch
Attachment 248753
[details]
did not pass mac-ews (mac): Output:
http://webkit-queues.appspot.com/results/6626488874958848
New failing tests: inspector-protocol/dom-debugger/node-removed.html
Build Bot
Comment 3
2015-03-16 15:42:00 PDT
Created
attachment 248758
[details]
Archive of layout-test-results from ews100 for mac-mavericks The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews100 Port: mac-mavericks Platform: Mac OS X 10.9.5
Build Bot
Comment 4
2015-03-16 15:44:49 PDT
Comment on
attachment 248753
[details]
Patch
Attachment 248753
[details]
did not pass mac-wk2-ews (mac-wk2): Output:
http://webkit-queues.appspot.com/results/5011494735446016
New failing tests: inspector-protocol/dom-debugger/node-removed.html
Build Bot
Comment 5
2015-03-16 15:44:53 PDT
Created
attachment 248759
[details]
Archive of layout-test-results from ews104 for mac-mavericks-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews104 Port: mac-mavericks-wk2 Platform: Mac OS X 10.9.5
Alexey Proskuryakov
Comment 6
2015-03-16 15:50:42 PDT
Oh wait, is it this patch that actually breaks inspector-protocol/dom-debugger/node-removed.html? I'm no longer sure if it was for a good reason that I disabled it in
bug 142753
.
Chris Dumez
Comment 7
2015-03-16 15:57:21 PDT
The attached results say the test fails with a timeout, it does not say anything about a crash.
Alexey Proskuryakov
Comment 8
2015-03-16 16:03:26 PDT
Yes, that's what it says. But if you look at the bot, there are crash logs.
Chris Dumez
Comment 9
2015-03-16 17:27:23 PDT
Created
attachment 248771
[details]
Patch
Antti Koivisto
Comment 10
2015-03-16 17:47:31 PDT
I already tried to do this in
bug 109765
. Didn't stick.
Antti Koivisto
Comment 11
2015-03-16 17:49:54 PDT
That patch also tries (and fails) to deal with nested runloops.
Build Bot
Comment 12
2015-03-16 18:14:50 PDT
Comment on
attachment 248771
[details]
Patch
Attachment 248771
[details]
did not pass mac-ews (mac): Output:
http://webkit-queues.appspot.com/results/5282230683303936
New failing tests: inspector-protocol/dom-debugger/node-removed.html
Build Bot
Comment 13
2015-03-16 18:14:53 PDT
Created
attachment 248773
[details]
Archive of layout-test-results from ews100 for mac-mavericks The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews100 Port: mac-mavericks Platform: Mac OS X 10.9.5
Chris Dumez
Comment 14
2015-03-16 18:15:28 PDT
(In reply to
comment #11
)
> That patch also tries (and fails) to deal with nested runloops.
Thanks for the pointer Antti. I wasn't aware this was previously tried. I'll still try and make it work as the performance gain seems worth it.
Build Bot
Comment 15
2015-03-16 18:22:01 PDT
Comment on
attachment 248771
[details]
Patch
Attachment 248771
[details]
did not pass mac-wk2-ews (mac-wk2): Output:
http://webkit-queues.appspot.com/results/4816377592414208
New failing tests: inspector-protocol/dom-debugger/node-removed.html
Build Bot
Comment 16
2015-03-16 18:22:07 PDT
Created
attachment 248775
[details]
Archive of layout-test-results from ews104 for mac-mavericks-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews104 Port: mac-mavericks-wk2 Platform: Mac OS X 10.9.5
Chris Dumez
Comment 17
2015-03-16 20:33:05 PDT
Created
attachment 248796
[details]
Patch
Chris Dumez
Comment 18
2015-03-16 20:52:28 PDT
Created
attachment 248798
[details]
Patch
Chris Dumez
Comment 19
2015-03-16 21:00:37 PDT
Created
attachment 248799
[details]
Patch
Chris Dumez
Comment 20
2015-03-16 21:03:18 PDT
Created
attachment 248800
[details]
Patch
Build Bot
Comment 21
2015-03-16 21:52:04 PDT
Comment on
attachment 248800
[details]
Patch
Attachment 248800
[details]
did not pass mac-ews (mac): Output:
http://webkit-queues.appspot.com/results/5369388454641664
New failing tests: fast/events/scroll-event-during-modal-dialog.html
Build Bot
Comment 22
2015-03-16 21:52:09 PDT
Created
attachment 248806
[details]
Archive of layout-test-results from ews101 for mac-mavericks The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews101 Port: mac-mavericks Platform: Mac OS X 10.9.5
Chris Dumez
Comment 23
2015-03-16 22:15:00 PDT
Created
attachment 248817
[details]
Patch
Chris Dumez
Comment 24
2015-03-16 22:29:48 PDT
Created
attachment 248824
[details]
Patch
Chris Dumez
Comment 25
2015-03-16 22:45:43 PDT
Created
attachment 248825
[details]
Patch
Chris Dumez
Comment 26
2015-03-16 22:49:51 PDT
Created
attachment 248826
[details]
Patch
Darin Adler
Comment 27
2015-03-16 23:43:10 PDT
Comment on
attachment 248826
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=248826&action=review
Seems really unfortunate that the iOS and Mac versions of this don’t share more code. I wonder if there is a way to do even better on this, cutting down on the repeated calls to CFRunLoopTimerSetNextFireDate somehow.
> Source/WebCore/platform/SharedTimer.h:79 > +#if PLATFORM(MAC) || PLATFORM(IOS)
Could use PLATFORM(COCOA) for this. We often do. Or we could just put empty removeSharedTimer functions into the other platform SharedTimer implementation files. Seems worthwhile to avoid the #if if at all possible.
Chris Dumez
Comment 28
2015-03-17 11:39:45 PDT
Created
attachment 248856
[details]
Patch
Build Bot
Comment 29
2015-03-17 12:29:47 PDT
Comment on
attachment 248856
[details]
Patch
Attachment 248856
[details]
did not pass mac-ews (mac): Output:
http://webkit-queues.appspot.com/results/4674012311453696
New failing tests: fast/events/scroll-event-during-modal-dialog.html
Build Bot
Comment 30
2015-03-17 12:29:52 PDT
Created
attachment 248860
[details]
Archive of layout-test-results from ews102 for mac-mavericks The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews102 Port: mac-mavericks Platform: Mac OS X 10.9.5
Chris Dumez
Comment 31
2015-03-17 13:28:55 PDT
Created
attachment 248864
[details]
Patch
Chris Dumez
Comment 32
2015-03-17 13:54:07 PDT
Created
attachment 248867
[details]
Patch
Chris Dumez
Comment 33
2015-03-17 14:31:55 PDT
Created
attachment 248870
[details]
Patch
Antti Koivisto
Comment 34
2015-03-17 15:54:14 PDT
Comment on
attachment 248870
[details]
Patch r=me, nice Did you test on iOS?
Chris Dumez
Comment 35
2015-03-17 15:56:40 PDT
(In reply to
comment #34
)
> Comment on
attachment 248870
[details]
> Patch > > r=me, nice > > Did you test on iOS?
Well, I tested a few sites. I initially wrote this optimization for bing.com on iOS.
WebKit Commit Bot
Comment 36
2015-03-17 16:43:22 PDT
Comment on
attachment 248870
[details]
Patch Clearing flags on attachment: 248870 Committed
r181671
: <
http://trac.webkit.org/changeset/181671
>
WebKit Commit Bot
Comment 37
2015-03-17 16:43:29 PDT
All reviewed patches have been landed. Closing bug.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug