Open Bug 1865542 Opened 3 years ago Updated 1 year ago

WebRender Android: much more jank @90 Hz than @60 Hz, Samsung/Mali

Categories

(Core :: Graphics: WebRender, defect)

Firefox 121
defect

Tracking

()

UNCONFIRMED

People

(Reporter: mark.paxman99, Assigned: jnicol)

References

(Depends on 1 open bug, Blocks 1 open bug)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:121.0) Gecko/20100101 Firefox/121.0

Steps to reproduce:

Galaxy M32, Mali, today's Firefox Android Nightly, 121.0a1 2015986727
Samsung gives two display refresh choices, Motion Smoothness "High" = 90 Hz, Motion Smoothness "Standard" = 60 Hz.
On many pages, scrolling is MUCH jankier at 90 Hz than at 60 Hz
eg https://blog.mozilla.org/en/category/products/firefox/
Many others too
Profiles attached
I wonder if it's something to do with vsync?

Actual results:

60 Hz is visually very smooth
https://share.firefox.dev/3QJIbEJ

90 Hz is visually very janky
https://share.firefox.dev/3QDTPB6

You can see it on the visual Profiler (about:config) too, at 60 Hz the Frame CPU Total at the top right is typically 7 ms and the Frame CPU Total graph shows almost no red bars (dropped frames). At 90 Hz Frame CPU Total is typically 14 ms and the Frame CPU total graph shows many many red bars (dropped frames).

None of the components in Frame CPU total list is very large, eg Frame Building ~1 ms, Renderer ~ 3 ms for both cases, everything else is tiny.

Expected results:

I would expect the CPU time to be independent of the refresh rate, WebRender has to do a fixed amount of work to render the frame and that is either more or less than the refresh period??

Why is WebRender taking about twice as long to render the same content when in 90 Hz refresh mode?

Thanks!

I wonder if there is a misunderstanding between WebRender and the Android graphics driver about what the refresh rate is?

The dropped frames seem to come in repeating cycles which makes me wonder if two clocks are rolling past each other.

And at 90 Hz the renderer seems to spend an awful lot of time trying to handshake with the graphics driver, eg android::IPCThreadState::talkWithDriver(bool). It doesn't do this at 60 Hz. Maybe at 90 Hz the graphics driver & WebRender disagree on when the refresh clock tick is due?

Of course, I don't know what I'm talking about ;)

Jamie, any idea what might be going on here?

Flags: needinfo?(jnicol)
Severity: -- → S2

It's butter smooth on my new Galaxy S21 FE at 120 Hz and at 60 Hz, few/no dropped frames.

Sorry it's taken me so long to have a look at this. I agree it looks like it's to do with vsync. Unfortunately the profiles aren't symbolicated correctly, however we can see in the 90Hz profile's flamegraph that it spends a lot more time dequeuing a buffer from the window system.

I wonder if we are perhaps slightly too slow to hit the 90hz target and therefore are oscillating between display rates, causing it to look janky. whereas we comfortably make the 60hz target so it appears smooth.

If you go to your phones developer settings and enable "Show refresh rate" then scroll around in firefox what does it show?

Flags: needinfo?(jnicol) → needinfo?(mark.paxman99)

heh, I now realise I basically just repeated what you said in comment 1 :)

I think my M32 does not have adaptive frame rate, it's locked at 90 Hz.

Would a symbolicated profile help? If so tell me what I did wrong last time.

Flags: needinfo?(mark.paxman99)
Depends on: 1878046
Assignee: nobody → jnicol

Hi Mark, sorry for the lack of update on this. I have been chipping away at it, but it's rather complex. Essentially on this device we are just about able to render many pages at 60Hz, but struggle at 90Hz. (Due to having 11ms to render each frame vs 16)

There are two approaches to fix this, and we need a combination of both. 1) Be faster. 2) Handle things better when we fall behind.

For the blog.mozilla.org page specifically, I fixed bug 1886739. For me on the same device, this allows smooth scrolling at 90Hz.

However, this is indeed a more general issue: on any device, regardless of how powerful, there will always be a certain complexity of page at which we cannot keep up with the display rate.

From some profiles I took with bug 1878046 (I haven't landed this yet as I'm still pondering how best to expose this data to the profiler), I gained some insight in to the long calls to eglSwapBuffers and eglQuerySurface().

eglSwapBuffers appears to block until the GPU work from the previous frame has completed. Essentially this happens when the GPU is overloaded. Presumably we see it more at 90Hz as the GPU has less time in which to complete the work without encountering this issue.

eglQuerySurface is called at the start of a frame when we query the buffer age. If we didn't query the buffer age, the samples would probably just shift to when we first render in to a surface, eg glClear(). This blocks until the EGL_DEQUEUE_READY_TIME_ANDROID timestamp for (usually) 3 frames prior has completed. This is when surfaceflinger has submitted the read commands for the buffer to be composited to the screen, meaning the buffer is now available for us to submit write commands to for the next frame. (we are typically triple-buffered). This tends to occur when, following a slow frame, we have a couple fast ones and therefore submit them faster than the display rate in an attempt to catch up. But the compositor cannot release new buffers to us any faster than the display rate, so we end up blocking here.

We also have a mechanism to skip a frame if we detect we are falling behind. This actually causes some of the visual stuttering - as we suddenly jump forward quite a bit. We have to drop frames somewhere in order to catch up, but perhaps this could be done more intelligently.

No solution yet I'm afraid, just a bit of a brain dump for now.

Thanks for the info, very interesting! I can barely follow.

I can confirm that on my M32 the blog.mozilla pages have got a lot smoother in today's Nightly compared with Beta and I can see the difference in the tiling with debug.picture-caching true.

Not sure what else I can add apart from I'm glad it resulted in a bug fix & better performance

I guess the Galaxy M32 is something of an edge case, it's got a fairly weak GPU but the option of 90 Hz. The 90 Hz is fixed, but I think many phones have variable refresh rate. In that case hypothettically you might make something where if Fenix is dropping a lot of frames it would request a drop using the frame rate API. But I bet that would be a huge amount of work for not very much gain.

Best

That explanation is fascinating, and might be a lead on the autoscroll stuttering bugs too.

Severity: S2 → S3
You need to log in before you can comment on or make changes to this bug.