Skip to content

DiffCallback for DrawerLayoutAdapter #1842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Vafeen
Copy link

@Vafeen Vafeen commented Feb 7, 2025

Why notifyDataSetChanged() is Suboptimal

Full Redraw: Calling notifyDataSetChanged() triggers a complete redraw of the entire RecyclerView, even if only a single item has changed.
Resource Intensive: This demands significant computational resources, particularly for large lists, as all items must be re-bound and re-drawn.
Undesirable Animations: A full redraw resets any animations associated with list items, leading to a visually jarring user experience.

Why DiffUtil is More Optimal

Precise Updates: DiffUtil calculates the minimal set of changes (additions, removals, changes, moves) required to transform the old list into the new list.
Targeted Operations: Based on these changes, the adapter uses notifyItemInserted(), notifyItemRemoved(), notifyItemChanged(), and notifyItemMoved() to update only the items that actually need updating.
Improved Performance: This significantly reduces the load on the system, resulting in a smoother and more responsive UI, especially with large lists or frequent data updates.
Preservation of Animations: DiffUtil preserves RecyclerView item animations, providing a more polished visual experience.
In summary, DiffUtil provides granular control over RecyclerView updates, minimizing the amount of work needed to refresh displayed data, in contrast to the all-or-nothing approach of notifyDataSetChanged().

@Vafeen
Copy link
Author

Vafeen commented Apr 18, 2025

@Arash63Dehghan
@DrKLO
@Bubu
@alabiaga
Hi, will it be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants