andreynovikov / trekarta

Simple, responsive map for your trek. You decide how to journey today, not the application!
https://trekarta.info
GNU General Public License v3.0
178 stars 25 forks source link

Performance issue when app goes to background #130

Open bardcrab opened 4 years ago

bardcrab commented 4 years ago

I have tested app on RPi3 B+ board with Lineage OS 17.1 and found that app tends to continuously drain CPU with activity from single thread when switched to background. Issue appears only when I trying to switch the app to background and in the same time map animation (dragging easing for example) was not finished. Profiling shows that performance eating routines for this issue located mostly in CrosshairLayer.animate.Runnable.run method. I have tweaked it a bit and added check to prevent animation of execution if main activity is not running:

public class CrosshairLayer extends Layer implements Map.UpdateListener {
...
        private void animate(boolean enable) {
            if (mRunAnim == enable)
                return;

            mRunAnim = enable;
            if (!enable)
                return;

            final Runnable action = new Runnable() {
                private long lastRun;

                @Override
                public void run() {
                    if (!mRunAnim || !MapTrek.isMainActivityRunning)    // <- fixed here
                        return;
...
}

Issue was gone after this fix, but I not sure that this is right way to fix it, because I not digged in code too much.

hungerburg commented 2 years ago

Finally came to test this: Put the device on USB, connect with adb, start top command. In Trekarta, pan map, put Trekarta to background, while animation active. See Trekarta use 100% CPU in top.

Will try the fix. Hopefully soon. I use Trekarta in places, where the next electric outlet is hours of walk away. I have learned to have a power block ready.