cloudstream icon indicating copy to clipboard operation
cloudstream copied to clipboard

Separate loading view from homepage

Open tuyafeng opened this issue 2 years ago • 5 comments

Thanks for your project, it helped me a lot.

I have a device with poor performance, when cloudstream is running on it, some operations cause stuttering, so I want to optimize its performance.

I first found that the home page has a lot of unnecessary loading status views, and we can remove them completely when the loading is over. I added a framelayout as the fragment's container, and loaded the loading state as a fragment into the container.

In this way we can separate the loading part from the home page, which will make the code more maintainable.

tuyafeng avatar Dec 24 '22 14:12 tuyafeng

Intresting

LagradOst avatar Dec 24 '22 15:12 LagradOst

Does it actually improve performance for you?

LagradOst avatar Dec 24 '22 15:12 LagradOst

I'm still working on other parts. This is just a small part. I did some simple measurements and below are my data.

Before the change, it takes about 350ms to load the layout (inflate view) on the homepage (on my xiaomi mi6 sagit), after separation, it takes 300ms to inflate the view, which is still time-consuming but helpful.

tuyafeng avatar Dec 24 '22 15:12 tuyafeng

In the next step, I plan to use constraint layout to reduce layout nesting, and use View+Drawable to replace the placeholder CardView, which should also help.

tuyafeng avatar Dec 24 '22 15:12 tuyafeng

Ok, sounds nice. I was planning on doing a tv homepage UI rework, but I will hold off on that while you do this

LagradOst avatar Dec 24 '22 15:12 LagradOst

Upon investigation it looks like the main culprit of slow load times is the main recyclerview not recycling as it's in a nested scroll view. This will get fixed soon.

Blatzar avatar Dec 27 '22 00:12 Blatzar

You can set the reuse pool of these recyclerviews to be the same. Going a step further, you can even use recyclerview nested recyclerview to implement the main page (of course, you also need to set their reuse pool to the same, which will make some Views enter the recycling stack).

Referer: RecyclerView#setRecycledViewPool

tuyafeng avatar Dec 27 '22 02:12 tuyafeng

But let's still pick up some cigarette butts and do small optimizations like splitting the home page state, which I think are good for maintaining the code and are not as heavy as the above mentioned optimizations and can be done easily. This PR is complete, you can merge it directly, of course, if you have a better way, you can also modify it after closing it. This is your project, feel free to do it.

tuyafeng avatar Dec 27 '22 02:12 tuyafeng

Don't get me wrong, this pr will get merged and I'm very thankful for it, I'll do a proper check tomorrow 🙏 I'm just informing you to get opinions and prevent double work

And I mean the vertical recyclerview, it's currently inside a nested scroll view to allow the top stuff to be displayed. If you got any ideas how to implement that without dragging the header logic inside the recyclerview itself it'd be a godsend 🙏

Rendering 18 rows at once is extremely heavy on the UI thread 💀

Blatzar avatar Dec 27 '22 02:12 Blatzar

I think the current approach is acceptable if you don't want nesting to optimize performance. ViewPager2 itself is a RecyclerView, sharing the reuse pool will help, and RecyclerView#setHasFixedSize will also help.

tuyafeng avatar Dec 27 '22 02:12 tuyafeng

Ill try to fix the conflicts soon

Blatzar avatar Jan 02 '23 12:01 Blatzar

closing as stale and outdated with the new binding system

LagradOst avatar Jul 31 '23 23:07 LagradOst