Reduced CPU usage when playing a video by 7-10% #4080
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is it?
Description of the changes in your PR
After reading this comment #3948 (comment)
I checked how much CPU the player uses. And found out that @MD77MD said incorrect information but even if it's not true (about double difference) the new player definitely uses more CPU than 0.19.8. Difference is about 15%. So I started seaching for the cause and found that this line https://github.com/TeamNewPipe/NewPipe/blob/dev/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java#L1774
adds 7-10% of CPU load. Actually there is no need to animate the progress bar when it's hidden under the video but it should be updated anyway (without animation) to reflect playing position changes.
Next. After this change the difference is still here but small: around 5%. Please, note, that I tested it on 5-year old phone while it had 1% of battery and worked on a charger with screen recorder impact so absolute values in your case would be less as well as difference.
I couldn't find a cause until I realized that MainVideoPlayer (old video player in 0.19.8) doesn't use notification. So it doesn't need to update it twice every second. This was it! After commenting out everything after this line: https://github.com/TeamNewPipe/NewPipe/blob/dev/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java#L640 the CPU usage was the same compared to 0.19.8 (0-1% difference).
Here is a screenrecord of comparison (with commented code related to notification) of new and old apps:
https://www.dropbox.com/s/l2sdo5rsjfmjusc/2020-08-05-12-01-09.mp4?dl=0
Of course this shouldn't be commented out in the current codebase but it gives us information about why this little difference exists: it's needed to update notification.
Testing apk
test-apk.zip
Agreement