bttv-android / bttv

A mod of the Twitch Android Mobile App adding BetterTTV, FrankerFaceZ and 7TV emotes
MIT License
636 stars 21 forks source link

App gets really laggy after using for some time #152

Closed chrisrnj closed 3 years ago

chrisrnj commented 3 years ago

Bug Report

Current Behavior If I use the app for 4 or 5 hours watching streams non-stop it gets pretty laggy, the fps for the stream and animations lower, my phone gets hot, and my battery is consumed faster than the official twitch app. This is easily fixed by restarting the app, after restarting the lag instantly stops and everything is smooth again.

Expected behavior/code Watch the streams without lagging, this issue doesn't happen in official twitch app.

Environment

FoseFx commented 3 years ago

So I did some profiling. I watched about an hour of different streams on two devices. An S8 (2017, 4GB RAM, 4x2.35GHz + 4x1.7GHz) and a Tab S6 (2019, 8GB RAM, 1x2.84 GHz + 3x2.42 GHz + 4x1.78 GHz). Here are my findings.

Performance on Tablet - 100k viewers

The first test I did was in some korean LOL stream which averaged 100k viewers during the test. After 53 mins all metrics were merely Identical to the beginning of the trace: tablet 1hr

11% CPU usage and low energy consumption.

Performance on Phone - 100k viewers

I then repeated the test as I could not identify any issues regarding performance, this time on my phone. And, well. The result were the same: phone 1hr

CPU consumption was a bit higher from the start though.

Stock app tablet

I noticed that I do not have anything to benchmark these results against, so I repeated the test again (on the tablet), this time using the base app. After 45 mins I gave up. Same results: Stock tablet 45 min

Gif Emotes

At some point I realized that, though the chat was quite active, they did not use that many BTTV emotes an pretty much none were animated. So later that day I joined a streamer with less viewers (avg. 3.5k) but much higher BTTV-Emote engagement.

Bildschirmfoto von 2021-06-26 23-20-06

As you can see CPU usage was much higher, about twice as high. Energy consumption was only marginally worse and still light.

Having a look at the CPU usage per thread revealed that about half of the consumed CPU time was used by the glide-animation thread: Bildschirmfoto von 2021-06-26 23-00-45

Glide is the library twitch used to render all emotes.

Conclusion

Clearly the increased CPU usage originates in the usage of (a lot) of Gif Emotes. This is expected, rendering these things is a non trivial task. This behavior does not get worse during runtime. I assume your CPU just starts overheating and thus throttles performance. This also explains why the reported times at which this behaviors starts differs wildly (4 hrs. vs 10 mins by other reports).

So what can be done? Very little. Twitch themselves have animated emotes, and yet they do not animated them (at least on my phone) because they are aware of the performance impact this can come with. If your device can't handle a chat room full of modChecks you should probably disable Gif Emotes in the BTTV settings. For next release #125 is in development, which would allow you to only render static versions of the emotes so you can at least have some of the BTTV experience.

chrisrnj commented 3 years ago

Alright, I look forward to the static gif emotes feature.

Jfamig commented 3 years ago

If there is no actual fix possible for the foreseeable future for this issue, would it be possible to add the animated/static toggle somewhere in the player settings (gear in top right of the video player) so it is something that could be easily toggled while watching the stream instead of digging into the app settings every time?

As you found, the problem is dependent on the BTTV usage of the channel. The idea is to be able to quickly toggle between static and animated on a per stream basis and I think this would significantly help mitigate the issue as much as possible for now.

xDevagya commented 3 years ago

idk how any of this works but if the issue is a lot of gifs then wouldn't it be possible to clear the gifs/chat after a certian interval, or only animate the gifs when they are in view?

NitroPlayz commented 3 years ago

This happens to me too in the app especially in active chats like xqc & forsen, using a S20 FE so it should be able to handle it. yet after a while it still starts to lag maybe adding a thing like @notDevagya Said would be a great solution

FoseFx commented 3 years ago

With the release of v0.14.0-beta bttv-android emotes behave like animated sub emotes and stop after some amount of time. (You can disable this if you want to). Does this fix the performance issues for y'all?

FoseFx commented 3 years ago

Feel free to reopen, when you still have issues, but this is fixed from my experiences!

ghost commented 2 years ago

Hi, Bringing this to your attention been using the lastest apk on the Samsung Galaxy Fold 3 usually watching streams with alot of bttv in chat and battery has been draining almost twice as fast as the Main Twitch app but the phone doesn't get hot or laggy while in use. Here's a screenshot of the battery usage. Screenshot_20220100-152057_Device care