airbnb / epoxy

Epoxy is an Android library for building complex screens in a RecyclerView
https://goo.gl/eIK82p
Apache License 2.0
8.5k stars 733 forks source link

Carousel models are rebuilt on scroll #849

Closed vipulyaara closed 4 years ago

vipulyaara commented 4 years ago

I am using a vertical recyclerView with many complex items. It has a horizontal carousel as its first item.

homepage.featuredPoets?.let { poets ->
            itemSpacing { id("spacing") }
            carousel {
                id("featured poets")
                withModelsFrom(poets) {
                    ItemPoetSliderBindingModel_()
                        .id(it.poetId)
                        .poet(it)
                }
            }
        }

when I scroll down, everything works fine and it scrolls smoothly. When I scroll up, the carousel models are built again and there is a jerk in scrolling. Profiler shows that this frame drop is due to layout measures. This happens for all the carousels and not for other items. These are the logs every time I scroll up (item size in carousel is 7)

D/SimpleEpoxyController: Models built: 0.117ms
D/SimpleEpoxyController: Item range inserted. Start: 0 Count: 7
D/SimpleEpoxyController: Models diffed: 0.154ms

Is this the desired behavior? I think models should not be rebuilt if underlying dataset is not changed.

elihart commented 4 years ago

The models are not actually rebuilt. You provide the models when the top level RV is built, so they already exist. What you are seeing is the carousel getting those models added to it the first time, which is just an "addAll" basically. note that the diff is just an insertion so it is very fast. this wouldn't be what is causing your issue.

You said yourself that profiling shows this is due to layout measures, which is separate from model building. Look into making the views inside your carousel more efficient in the measure pass

vipulyaara commented 4 years ago

Okay. This seems to be some problem specific to my carousels. I even tried with empty XMLs. I will run some more tests to figure out. Thanks