almindor / harbour-jTox

Sailfish OS native tox implementation for Jolla
GNU General Public License v3.0
12 stars 4 forks source link

High cpu usage #59

Open Michal-Szczepaniak opened 6 years ago

Michal-Szczepaniak commented 6 years ago

I noticed that jtox has static usage of 5-6% cpu on snapdragon 810 which causes lower battery life. We need to find out what does that and mininalize that.

almindor commented 6 years ago

Yes this is mostly toxcore. I have to "poll" toxcore every once in a while to keep online and get notified. I've tried to minimize impact by making the interval fairly long but tox/toxcore is simply not mobile-ready yet.

It does a whole lot of onion network DHT stuff and depending on the # of your friends grows in both network and CPU activity.

Michal-Szczepaniak commented 6 years ago

Is there no like toxcore callbacks to use instead of polling?

almindor commented 6 years ago

It already uses callbacks but the logic is like this:

  1. register for an event passing a callback function to toxcore
  2. call main "loop" function in toxcore
  3. event handler inside the main loop will call your event callbacks

The design is not "wrong" per se but they should provide the option to run this blocking so it can be put in a thread loop and wait for actual external events (networking etc.). My understanding is that because it's mostly UDP they need to actually periodically send pings to peers etc. so it cannot just "sit and listen for new packets". There's also the whole DHT facilitation but I'm not familiar enough to know what it entails.

There are a lot of issues open on their tracker related to performance/resource usage. See for example issue 441

Michal-Szczepaniak commented 6 years ago

So its more about toxcore than jtox itself is what you mean? Issue linked talks more about network usage rather than cpu usage tho

almindor commented 6 years ago

Sure but the CPU is most probably related to this event loop. Also the amount of networking resources is way past what you can afford on a phone (unless on wifi). It's just no there yet. You can try and "disconnect" the event loop after some amount of time to see if it stops the CPU. If you do find out it's not related I'm all about fixing of course.

Michal-Szczepaniak commented 6 years ago

Well purple have loop too and its working fine. Ill grab basic example and test using it and let ypu know if i find something.

almindor commented 6 years ago

Sure, thanks. I'm fairly sure that apart from the toxcore loop nothing should be executing. The only other things are animations but I'm fairly sure they get paused if you minimize the app and only happen in specific cases (e.g. offline msg. waiting to be sent etc.)

If you do find it's something out of toxcore I'll be more than happy to fix it.