Improve Recycler View Performance

Updated 25 March 2021

Save

This blog covers how we can Improve Recycler View Performance. Recently, I’ve been working on an application that has a vertical list in which every item has again a vertical/grid list. I faced recycle view performance problem. It didn’t scroll smoothly. When I scrolled it, it took time to render the items & I faced issue in smooth scrolling.

How RecycleView Works 

When we scroll down/up recycleview, the item which moved out from the visible screen becomes scrapped view. For loading the next coming item on screen, recycleview uses scrapped views collection. The view which loaded from scrapped views collection is called dirty view. This selected view is recycled and shown on screen.

Suppose, we have list of 100 items. 5 items can be shown on screen at a time. Currently, we are showing 11-15 items.

When we scroll down, item 12 to 16 will be shown on screen and item 11 will be moved out from visible screen. This item 11 will become scrapped view. If we again scroll down, then item 12 will also become scrapped view and items 13-17 will be shown on screen. We have collection of scrap views: item 11 & 12.

Now for item 18, one of scrap view item will be selected & recycled to show on the screen. This selected item will be called dirty view.

Top to bottom scrolling 

When we scroll items from top to bottom, tell recycleview to load offscreen items in advance. Through which, we can save view recycling time while scrolling & scrolling will become smooth.

We can create our custom LinearLayoutManager & set setExtraLayoutSpace.

Bottom to top scrolling 

Set the number of offscreen views to retain before adding them to the potentially shared recycled view pool.

Suppose, currently item 41-45 are showing on screen. When we scroll bottom to top, if old item will remain in cache then they will be shown easily on screen without any recycling of views or we can say without calling onBindViewHolder(). So for smooth scrolling, we can increase the cache size.

Through these two solution, we can Improve Recycler View Performance.

To learn more about recyclview, please check following link : Recycle View

Hope, this blog will be helpful to you.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home