RecyclerView vs ListView: Deep Dive into Caching and Partial Refresh Performance

This article compares Android's RecyclerView and ListView caching mechanisms, explains their multi‑level caches, shows how RecyclerView enables efficient partial refreshes, and concludes when each widget is appropriate based on performance and animation needs.

Tencent TDS Service
Tencent TDS Service
Tencent TDS Service
RecyclerView vs ListView: Deep Dive into Caching and Partial Refresh Performance

Background

RecyclerView is Google's official widget for displaying large data sets, intended to replace ListView with more power and flexibility.

The author investigates whether ListView should be replaced by RecyclerView from a performance perspective, focusing on their caching mechanisms.

Main Content

Cache Mechanism Comparison

RecyclerView has a four‑level cache (including a shared RecyclerViewPool) while ListView uses a two‑level cache. Both have similar concepts: active views, attached scrap, and cached views, but RecyclerView adds a cache of ViewHolders and a pool that can be shared across multiple RecyclerViews.

ListView obtains cached views via mScrapViews and always calls getView, which may re‑bind the view. RecyclerView obtains cached ViewHolders via mCacheViews, matching position and flag, allowing reuse without re‑binding when data does not change.

// AbsListView source snippet
final View scrapView = mRecycler.getScrapView(position);
final View child = mAdapter.getView(position, scrapView, this);
if (scrapView != null) {
    if (child != scrapView) {
        mRecycler.addScrapView(scrapView, position);
    } else {
        ...
    }
}

Partial Refresh

RecyclerView provides partial‑refresh APIs (e.g., notifyItemRemoved) that avoid unnecessary bindView calls. The refresh process goes through three layout steps: dispathLayoutStep1 records item positions, dispathLayoutStep2 measures and lays out children, and dispathLayoutStep3 computes item state changes and runs animations.

During notifyItemRemoved, RecyclerView updates item positions and flags before calling getViewForPosition, ensuring bindView is invoked only once.

Conclusion

For static lists or infrequent updates, ListView and RecyclerView perform similarly, and ListView may be simpler to use. When the list requires animations, frequent data changes, or partial updates (e.g., live comments), RecyclerView is recommended for its richer caching and flexible refresh capabilities.

performanceAndroidCachingRecyclerViewListViewPartial Refresh
Tencent TDS Service
Written by

Tencent TDS Service

TDS Service offers client and web front‑end developers and operators an intelligent low‑code platform, cross‑platform development framework, universal release platform, runtime container engine, monitoring and analysis platform, and a security‑privacy compliance suite.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.