4.2 RecyclerView Performance

For a RecyclerView, each item in the dataset is represented by a cell in the list. Only the cells that are immediately visible to the user are created at runtime; the hidden cells will be rendered as you scroll. This is how the compiler handles the rendering of the list.

Performance with RecyclerView

The recycler view only creates the cells that are immediately visible to the user, but the recycler view utilizes the ViewHolder pattern, a holder for cell metadata that maximizes performance by reducing the amount of times that view.findViewById() is called by the system. As the user scrolls, the recycler view will either create new view holders as necessary or reuse the view holders that have been offscreen the longest. By reusing view holders, we can reduce the number of calls to view.findViewById().

Why use RecyclerView over Alternatives?

RecyclerView has many in-app memory optimization that is already completed for developers. For example, RecyclerView forces developers to use the ViewHolder pattern.

RecyclerView was created as a direct enhancement to ListView which we will learn about in lecture 5 and thus, RecyclerView is easier to use and manipulate for complex lists. However, as you will see in Lecture 5, there will be instances where it makes more sense to use a ListView to save development time, like with the menu in Eatery. We'll go into more detail about this in the next section.

Last updated