In my Android app i'm showing data in a RecyclerView
using Room and the Paging library.
My implementation is quite similar to the example in the AsyncPagedListDiffer
docs.
The flow is the following:
- Data is changed in the database
A corresponding
Observer
passes the changes to theAdapter
:myLiveData.observe(viewLifecycleOwner, Observer { myAdapter.submitList(it) })
The
AsyncPagedListDiffer
calculates the diff and updates the list accordingly
My problem is the performance hit of step 3.
Even if i insert just one single item to the top of the list, the differ have to check all of the items (which is quite inefficient, especially with larger datasets), whereas a simple notifyItemInserted(0)
call would be sufficient.
Is there a way around this behavior?
For example, can i tell the differ that it doesn't have to check all of the items? Or any other solutions to this?
I'd really appreciate any advice.