Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Big performance issue #115

Open
SkyleKayma opened this issue Feb 9, 2020 · 1 comment
Open

Big performance issue #115

SkyleKayma opened this issue Feb 9, 2020 · 1 comment

Comments

@SkyleKayma
Copy link

I am trying the Scale layout manager, and there is a lot of performance issue.

For a list of 2 items, my onCreateViewHolder is called 6 times instead of 2 !
Items in viewpool are completly ignored too.

Someone have already encountered something like that ?

@SkyleKayma
Copy link
Author

SkyleKayma commented Feb 11, 2020

Ok, so it was not easy, but I found the issue.

In ViewPagerLayoutManager file, on method onLayoutChildren, you are calling :
View scrap = getMeasureView(recycler, state, 0);

So you are creating the view at index 0.
That's fine.
Then at the end of the method, you are calling :
layoutItems(recycler);

Ok that's fine too, but in this method you are calling :
recycler.getViewForPosition(adapterPosition)

And that's the issue ! You are creating another time the index 0 that you previously created in method just before. By doing this, with only 3 items shown, we are calling onCreateViewHolder of Adapter 1 time more.

To avoid that, you could just do something like this:

private void layoutItems(RecyclerView.Recycler recycler, @Nullable View scrapBis) { ...

final View scrap;
if (scrapBis != null && adapterPosition == 0) {
    scrap = scrapBis;
} else {
    scrap = recycler.getViewForPosition(adapterPosition);
}

... }

And in onLayoutChildren method do something like this :

layoutItems(recycler, scrap);

And elsewhere just pass null as second argument.
By doing this, during my test, i'm now getting only 3 creations instead of 4.

What do you think of this ? @leochuan

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

No branches or pull requests

1 participant