Bug 234923 - REGRESSION (iOS 15 / r275792): rAF sometimes seems to lose connection to v-sync signal and runs at < 60 fps
Summary: REGRESSION (iOS 15 / r275792): rAF sometimes seems to lose connection to v-sy...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Canvas (show other bugs)
Version: Safari 15
Hardware: iPhone / iPad iOS 15
: P2 Major
Assignee: Simon Fraser (smfr)
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-01-06 07:31 PST by Simon Taylor
Modified: 2022-07-11 03:29 PDT (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Taylor 2022-01-06 07:31:39 PST
On some navigations the rAF loop on iOS 15.2 runs at less than the v-sync rate.

The page below has a rAF callback that doesn't do anything apart from busy-loop for 8ms:
https://tango-bravo.net/webkit-bug-234303/raf_busyloop.html

This appears to be the behaviour, 100% reproducible from a clean start on iPhone 12 Pro and other iOS 15.2 devices (Safari killed, no tabs open, even cleared all data and rebooted first but this isn't necessary):

1) Visit this bugzilla page
2) Click the link above to the no-op demo page
3) Note rAF loop runs at 60 FPS
4) Back to this page
5) Click the link again (or another one on the same domain, eg https://tango-bravo.net/webkit-bug-234303/clear_color_cycle_busyloop.html )
6) Note rAF now runs at <60 FPS. <60FPS persists through refresh, background / foreground app switch, history navigation.
7) Kill Safari (still with tab open) and re-open. Back to 60 FPS.

It appears that the affected tab is somehow disconnected from the display v-sync signal, and instead waits ~16.6ms from the end of the previous rAF callback before triggering the following one (hence the whole loop running at <60FPS).

Could it perhaps have something to do with content process isolation, when switching back to an existing content process from another domain? (I don't even know if WebKit does that but know it's a thing in Chrome)

Copying/pasting the URL from a <60FPS tab into a new one also gets 60FPS, so seems something to do with the Tab & Domain combo that is affected.
Comment 1 Alexey Proskuryakov 2022-01-07 17:50:44 PST
Thank you for the report! Could you please confirm if this issue is new in iOS 15.x, or if it affected earlier versions too?
Comment 2 Simon Taylor 2022-01-12 09:36:05 PST
(In reply to Alexey Proskuryakov from comment #1)
> Thank you for the report! Could you please confirm if this issue is new in
> iOS 15.x, or if it affected earlier versions too?

I think it's a 15.x regression - I can't reproduce on a 14.8.1 iPhone 12 mini.

100% reproducible on iPhone 12 Pro and iPod touch 7th gen, both on 15.2. I don't have any devices on other 15.x releases I'm afraid.

In terms of relation to Bug 235114 - they are distinct, but both hinting at issues on tabs becoming foregrounded.

If you go back and forth to the demo on that page, you can repro this bug too. Note in "normal" case the rAF loop is < 60 FPS on the Bug 235114 demo page though - that's on purpose to trigger high clocks and keep the CPU busy. So that demo is typically 50 FPS unless this bug is also in play, when it'll drop to 25 FPS.
Comment 3 Radar WebKit Bug Importer 2022-01-12 09:56:55 PST
<rdar://problem/87465488>
Comment 4 Simon Taylor 2022-01-13 03:09:24 PST
> (In reply to Alexey Proskuryakov from comment #1)
> > Thank you for the report! Could you please confirm if this issue is new in
> > iOS 15.x, or if it affected earlier versions too?
> 
> I think it's a 15.x regression - I can't reproduce on a 14.8.1 iPhone 12
> mini.
> 
> 100% reproducible on iPhone 12 Pro and iPod touch 7th gen, both on 15.2. I
> don't have any devices on other 15.x releases I'm afraid.

It does also reproduce on the 15.0 Simulator if that helps narrow things down at all.
Comment 5 Simon Taylor 2022-02-16 02:53:10 PST
Still reproduces easily in iOS 15.4 beta 3, iPhone 12 Pro.
Comment 6 Simon Taylor 2022-02-28 04:07:17 PST
Still with us on 15.4 beta 4 (verified on iPod touch 7th gen).
Comment 7 Antoine Quint 2022-03-21 07:10:05 PDT
RemoteLayerTreeDisplayRefreshMonitor::requestRefreshCallback() returns false because there is no m_drawingArea. As a result RenderingUpdateScheduler::scheduleRenderingUpdate() falls back to using a timer.
Comment 8 Antoine Quint 2022-03-21 12:09:35 PDT
This regressed with r275792, the fix for bug 224395.
Comment 9 Simon Fraser (smfr) 2022-07-05 22:11:02 PDT
Pull request: https://github.com/WebKit/WebKit/pull/2113
Comment 10 EWS 2022-07-06 14:36:13 PDT
Committed 252188@main (0842b6a96626): <https://commits.webkit.org/252188@main>

Reviewed commits have been landed. Closing PR #2113 and removing active labels.
Comment 11 Simon Taylor 2022-07-08 02:42:25 PDT
Great, thanks for the fix.

Another potential related issue that was much harder to reproduce - occasionally when initially viewing a tab (I commonly access pages via QR scans in the camera, and often from the same domain) I've seen it look like it's being actively throttled with a lower rAF rate - almost as if Webkit considers the tab to be a background one.

Looking at the commit message (with a very limited understanding) - is it possible the same underlying bug might have caused this behaviour?
Comment 12 Simon Fraser (smfr) 2022-07-08 10:14:59 PDT
It's possible, but if you can figure out steps to reproduce this reliably I can test it.
Comment 13 Simon Taylor 2022-07-11 03:29:01 PDT
I wasn't able to find reproduction steps last time I tried - it might be that Safari needs to have been idle for a while with some particular state of open tabs to trigger it, or it might just be something timing related that makes it not very reproducible anyway.

Once this fix ships in an iOS release I'll keep my eye out for it.