Image for post
Image for post

RecyclerView Prefetch

Smoother Flings and Scrolls by Doing Stuff Sooner

Chet Haase
Dec 21, 2016 · 7 min read

The Problem

Image for post
Image for post
Typical rendering phases of RecyclerView content during a scroll (as of the Lollipop release). On the UI thread, we process input events, handle animations, perform layout, and record the drawing operations. Then the RenderThread (RT) sends the commands to the GPU.
Image for post
Image for post
New items cause the Input stage to take longer as new views are created, bound, and laid out. This results in a later start for the Render stage, which might cause it to finish after the frame boundary, resulting in a missed frame.
Image for post
Image for post
The call stack during input shows that new items coming into view cause a large chunk of time to be spent creating and binding the new views
Image for post
Image for post
Creating and binding views has to be done before they can be rendered, which takes up valuable time on the UI thread during the frame in which they’re needed. But meanwhile, that thread spends a lot of time idling in the previous frame…

The Solution

Image for post
Image for post
Moving the creation and bind operations to the previous frame allows the UI Thread to do that work in parallel with the RenderThread, and avoids doing it later when it has to be done synchronously before the RenderThread can draw the results.

Details, Details

Caveats

I Want Some — Where Can I Get It?

Image for post
Image for post
Systrace showing prefetch occurring during the otherwise idle time of the UI thread

GOTO End

Google Developers

Engineering and technology articles for developers, written…

Chet Haase

Written by

Android and comedy. Not necessarily in that order.

Google Developers

Engineering and technology articles for developers, written and curated by Googlers. The views expressed are those of the authors and don't necessarily reflect those of Google.

Chet Haase

Written by

Android and comedy. Not necessarily in that order.

Google Developers

Engineering and technology articles for developers, written and curated by Googlers. The views expressed are those of the authors and don't necessarily reflect those of Google.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store