3% CPU in idle state on Android with Crosswalk webview

Hey !
I’m trying to understand why my ionic app keeps using 2%~5% CPU without doing anything, draining the battery with no reason.
image
Actually, It used to be ~8% CPU when in idle state, but i figured out it was because of the $ionicLoading service with an embedded SVG spinner that was continuously animated, even when hidden. I figured this out using Chrome profiling tools. I ended up implementing my own loading component.
Now, i still have these 3-5% CPU activity while in idle state with profiling tools showing absolutely no activity:


No timers, no CSS animations, … nothing.

Could someone help me find out what is going on ? could this be related to the use of the crosswalk webview ? has anybody ever experienced such an issue ? Are there any other ways to profile CPU usage except using chrome dev tools ?
Thanks !

Does anyone have any clue on this point ? I feel quite lonely on this :grin:

Your app is probably rendering something, keeping state, watching for push notifications, utilizing native API’s. That 3% won’t go away unless you find a way to literally stop your app and crash it. Also Ionic being built on Angular, angular has it’s own loops and events it’s keeping track of in the lowest level angular code. Otherwise your app would not respond to touch, alerts, etc.

Thanks for your answer, i don’t feel lonely anymore :smile:
Then if this activity is due to rendering or some javascript code execution within angular, how come i can’t see anything in chrome profiling tools ?
Do you mean it’s related to cordova plugins constantly doing things, even with the app being in background ? that would explain why it doesnt appear in chrome dev tools though.
Is there a way to force the app to pause when in background ?
Would you know a way to track cordova plugins activity and see which is consuming CPU ?

Thanks

You got it, it’s probably partially how Android renders the web view even in the background (to keep things current with the javascript so that when the app does resume that it’s at the correct rendered state) and the cordova plugins. The only way I can think to track cordova plugins is by using some sort of Android debugging tool and run the app on the device. I primarily use Xcode in my development and they have some amazing profiler tools that tell you what processes and things are taking up memory, CPU, etc and I’m sure there is something for android.

And as for the pausing, I’m not sure. Android/iOS will automatically slow things down and put the app in the ‘idle’ state, but just like idling a car, it’s still using a really really small amount of gas.

It might not even be a specific cordova plugin, but cordova itself probably listens to some events and has some sort of processing going on to link your web view with the native os. I would look more into the native side of these things and the cordova side, it probably isn’t much to do with your actual JS that you’re writing or running.

Then if it’s related to cordova or some hidden under the hood process, I guess there’s not much I can do to avoid that. That’s bad news for me. I’ll keep looking for a solution anyway. As a last resort I think i’ll advise users to close the app when they’re not using it.
Thanks for helping.

No problem, and I suspect that the platforms will terminate the app if it hits a memory pressure from other apps opening, so I would maybe try and find how long android holds that open with one of those debugger tools.

This is quite old question, but I have come to same thing. My ionic app had constantly about 5% CPU even in idle state on background. After hard debugging I have found two things what makes the CPU.

  1. animated gif image

  2. bug in ionic wrapper of device motion cordova plugin (acceleration watcher never stop then)

  3. animated gif: I had animated gif as loading spinner in my index.html while my app becomes available. On mobile phones it was not visible at all, because splash screen is turned off after app init, but it was for browser use. Removing this gif solves about 3% CPU

  4. I have device motion plugin in my app and I was using it as described in ionic docs, so if not needed anymore I have called unsubscribe. But ionic was not calling clearWatch method correctly (with wathID parameter), so the watcher never stops. It caused another ~3% CPU. As an workaround I have used plugin directly, bypassing ionic wrapper as described in cordova docs.

Removing those two problems I get approximately 0.4% CPU which I think is the lowest minimum, because I have tested empty index.html builded into cordova app even without the crosswalk and still getting the minimum 0.4% CPU usage.

Hope that this help someone else, happy coding :wink: