Skip to content

Major performance and bug fixes to downloads #1164

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

Merged
merged 10 commits into from
Jul 4, 2024

Conversation

Luna712
Copy link
Contributor

@Luna712 Luna712 commented Jul 1, 2024

I tracked down underlying issues to setPersistentId. So I instead improved this using IO context, and this makes it use the view model more when in the downloads view, because otherwise when running savedData in an IO context it causes it to wait before updating progress which causes visible UI delays. This prevents that with downloads with the IsDone status.

This also has a UI change: If a download is complete, it no longer shows bytes / bytes, it only shows bytes once. This is both a UI and performance improvement to have to do less. Finally, this does some cleanup to DownloadAdapter and DownloadViewModel as well and fixes the display of the no downloads messages which previously seemed to have intended implementation but did nothing.

This also fixes the underlying cause of many bugs like the byte mismatch, while my previous fix for that was just a patch-job, this should fix the underlying cause of them as well.

Overall when testing this makes downloads load with almost no lag at all now.

I tracked down underlying issues to setPersistentId. So I instead removed that entire function here and instead we send the byte data from the view model to it. This also does minor improvements to view model.

This also fixes the underlying cause of many bugs like the byte mismatch and icon bug, while my previous fix for that was just a patch-job, this should fix the underlying cause of them as well.

Overall when testing this makes downloads load with 100% zero lag now.
@Luna712
Copy link
Contributor Author

Luna712 commented Jul 1, 2024

I just realized this has some big issues with it... my bad...

@Luna712
Copy link
Contributor Author

Luna712 commented Jul 1, 2024

There has got to be a way to make it work... but this way breaks in progress downloads indicator and download progress in EpisodeAdapter, etc... so is not the way to do it. But there must be a way to make this performant...

@fire-light42
Copy link
Collaborator

There has got to be a way to make it work... but this way breaks in progress downloads indicator and download progress in EpisodeAdapter, etc... so is not the way to do it. But there must be a way to make this performant...

Try doing it in a IO context then switch back to main thread as getDownloadFileInfoAndUpdateSettings checks the file on disk and doing that on the main thread lags it.

…more in IO context


This makes it use the view model more when in downloads view, because otherwise when running savedData in an IO context it causes it to wait before updating progress which causes visible UI delays. This prevents that with downloads with the IsDone status.

This also has a UI change: If a download is complete, it no longer shows bytes / bytes, it only shows bytes once. This is both a UI and performance improvement to have to do less. Finally, this does some cleanup to DownloadAdapter.
@Luna712
Copy link
Contributor Author

Luna712 commented Jul 1, 2024

There has got to be a way to make it work... but this way breaks in progress downloads indicator and download progress in EpisodeAdapter, etc... so is not the way to do it. But there must be a way to make this performant...

Try doing it in a IO context then switch back to main thread as getDownloadFileInfoAndUpdateSettings checks the file on disk and doing that on the main thread lags it.

@fire-light42

Done but a bit different as when just doing that it caused a delay where all icons showed the default download icon, for a noticeable time when opening downloads so I made it use the view model where possible. If you want me to do this another way I can certainly give it a try.

Copy link
Collaborator

@fire-light42 fire-light42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, this PR does not work in a recyclerview as views do not invalidate themself, presumably because of if (progressSet) return.

I wont merge this PR before ALL recyclerview problems are solved BOTH in downloads and resultpage.

@Luna712
Copy link
Contributor Author

Luna712 commented Jul 2, 2024

Nope, this PR does not work in a recyclerview as views do not invalidate themself, presumably because of if (progressSet) return.

I wont merge this PR before ALL recyclerview problems are solved BOTH in downloads and resultpage.

This does work for me when testing though... in both places...

@fire-light42
Copy link
Collaborator

Nope, this PR does not work in a recyclerview as views do not invalidate themself, presumably because of if (progressSet) return.
I wont merge this PR before ALL recyclerview problems are solved BOTH in downloads and resultpage.

This does work for me when testing though... in both places...

No. Try downloading an episode in a long running series and then flip between the seasons. I was able to reliably make it show it is currently downloading an episode (or several) on other seasons from 1 download. You MUST use something like if (id == persistentId) return instead.

@fire-light42
Copy link
Collaborator

Properly using recycleviews without invalid data or memory leaks can be a real PITA to find, debug and resolve. Therefore it is extra important to verify that all UI is re-rendered on bind if it is a different item.

@Luna712
Copy link
Contributor Author

Luna712 commented Jul 2, 2024

I can't seem to reproduce that but I do see how the issue could potentially happen. I will push a fix in a little bit.

@Luna712
Copy link
Contributor Author

Luna712 commented Jul 2, 2024

@fire-light42 I think the issue you had may be fixed, but I still could not reproduce to confirm

@Luna712 Luna712 requested a review from fire-light42 July 2, 2024 16:10
Copy link
Collaborator

@fire-light42 fire-light42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code works and looks good. However I found an issue that also needs fixing, after further testing I found a bug that has been in cs3 for some time. It might be good to solve it, however I am now unsure if it is UI or downloader related

The issue is as follows:

  1. Go into a resultpage with multiple seasons
  2. Download any episode
  3. Force quit
  4. Reenter the app and all download will automatically resume
  5. Go into the same series
  6. Pause that download
  7. Switch to another season
  8. Switch back to the season

If you do this correctly then you will see that the progress on the paused download does not match with the progress downloaded and it will need to resume to update to the correct progress.

error.mp4

Copy link
Collaborator

@fire-light42 fire-light42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ye, the issue I found is not related to this or your last pr but might need an real https://github.com/recloudstream/cloudstream/issues issue.

@Luna712
Copy link
Contributor Author

Luna712 commented Jul 4, 2024

Ye, the issue I found is not related to this or your last pr but might need an real https://github.com/recloudstream/cloudstream/issues issue.

@fire-light42

That's a good catch. I will try and fix that in a follow-up as well. But I'd rather not further complicate things in this PR and I'm not sure how to fix it at the moment.

@fire-light42 fire-light42 merged commit 03b8b6e into recloudstream:master Jul 4, 2024
2 checks passed
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.

None yet

2 participants