Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
New Contributor
justinw0320
Posts: 6
Registered: ‎10-19-2013
My Device: Z10
Accepted Solution

Alchemy library running slow when app deactivated in release build

Hi,

 

I am working on an app which does long running operation via an Alchemy library (written in C and exposed as .as).

 

Here's the high-level logic to illustrate the idea:

 

QNXSystem.system.inactivePowerMode = QNXSystemPowerMode.NORMAL;

addEventListener(AlchemyLibraryEvent.PROGRESS, onProgress);

addEventListener(AlchemyLibraryEvent.COMPLETE, onComplete);

Call Alchemy library;

 

private function onProgress(event: AlchemyLibraryEvent) {

     update progress in UI;

}

 

private function onComplete(event: AlchemyLibraryEvent) {

     QNXSystem.system.inactivePowerMode = QNXSystemPowerMode.STANDBY;

     if app is in Deactivated state {

            QNXSystem.system.powerMode = QNXSystemPowerMode.STANDBY;

     }

}

 

In bar-descriptor:

         <permission>run_when_backgrounded</permission>

 

What happens is that the app runs perfectly fine (no matter app is active, deactivated, device on standby) in a debug-build (with debug token).  However, when it is exported as signed bar and run on the same physical BB10 device, it works normally only when the app is active.  Whenever the app is deactivated (either when screen is off, or app being pushed to background and another app is brought to foreground), the app still runs but at an extremely slow speed (about 1/15 of the original speed).

 

I did some debugging and confirmed that when the app is deactivated, it was still running with NORMAL power mode at 60fps frame rate, which seems to be perfectly normal.  What I don't understand is why the Alchemy library is running so much slower in the background in release build.

 

As a proof of concept I added the following code just before setting inactivePowerMode to NORMAL:

NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

 

The release build version then runs at normal speed and the screen doesn't go off.  However, if I press the device power button, or push the app to background (and make another app in foreground), the same slow-running behavior recurs.

 

Any idea would be very much appreciated!!!

 

 

Please use plain text.
BlackBerry Development Advisor
twindsor
Posts: 832
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: Alchemy library running slow when app deactivated in release build

Applications running in the background have reduced CPU time limits compared to foreground applications. I think that's what you are seeing here. 

Tim Windsor
Open Source Technical Lead
Please use plain text.
New Contributor
justinw0320
Posts: 6
Registered: ‎10-19-2013
My Device: Z10

Re: Alchemy library running slow when app deactivated in release build

Hi Tim,

 

Thank you so much for your advice!  I think that makes sense because the part that is significantly slower when deactivated is a CPU intensive operation.  If it is given less CPU time, it is not surprised that it takes so much longer.

 

Does that mean even if I have power mode set to NORMAL and the app running at 60 fps when deactivated, it doesn't  mean that it is given as much CPU time as when it is activated?  Is there any way to force the OS to give full CPU time in deactivated mode?  If not, looks like the only way is to keep the app awake?

 

Thanks again.

 

 

Please use plain text.
BlackBerry Development Advisor
twindsor
Posts: 832
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: Alchemy library running slow when app deactivated in release build

No, there's no way to take more CPU power when in the background. The OS enforces this for the user, so they don't have apps churning through their battery on them. I would recommend that you inform your users of this, so they can decide what they want to do. BlackBerry 10 is intended for multi-tasking though, so I expect they will take advantage of it and put the app in the background.

Tim Windsor
Open Source Technical Lead
Please use plain text.
New Contributor
justinw0320
Posts: 6
Registered: ‎10-19-2013
My Device: Z10

Re: Alchemy library running slow when app deactivated in release build

Thanks Tim!!

 

Please use plain text.