Click To Start Your BlackBerry 10 Cascades Apps In No Time Flat With Zygote

Cascades

TITLE_IMAGE

Guest post from Roberto S. – Ed.

Since the introduction of Cascades in May, developers have been asking us one question: Is there something I can do to make my app start faster? Cascades is a marvelous piece of technology, but like any new technology, it takes time to work out the kinks and optimize performance. It took a while, but the Cascades team figured out a way to make it faster. Let me introduce you to Project Zygote.

When a detailed performance analysis was conducted on a Cascades application while it was starting up, it was discovered that loading shared libraries was taking up the majority of time. Cascades uses a number of different Qt and platform-specific libraries, so this made sense. After some investigation, we learned that you can save a lot of time by pre-compiling these shared libraries into one library that could be pre-loaded. Thus, Project Zygote was born.

How do you get in on the party? With this latest beta release of BlackBerry 10, all new Cascades projects will have Zygote enabled by default. You get it for free!

For those with pre-existing projects, there are some minor changes you need to make to your existing projects to enable Zygote for your release target. A little bit of work that goes a long way!

Let’s start by looking at the original project file for the Cascades Cookbook sample app:

TEMPLATE = app
TARGET = cascadescookbookqml

CONFIG += qt warn_on debug_and_release cascades

INCLUDEPATH += ../src
SOURCES += ../src/*.cpp 
HEADERS += ../src/*.h 

device {
	CONFIG(release, debug|release) {		
		DESTDIR = o.le-v7		
	} 
	CONFIG(debug, debug|release) {
		DESTDIR = o.le-v7-g
	}
}

simulator {
	CONFIG(release, debug|release) {
		DESTDIR = o
	} 
	CONFIG(debug, debug|release) {
		DESTDIR = o-g
	}
}

OBJECTS_DIR = $${DESTDIR}/.obj
MOC_DIR = $${DESTDIR}/.moc
RCC_DIR = $${DESTDIR}/.rcc
UI_DIR = $${DESTDIR}/.ui

As mentioned earlier, Zygote is configured primarily for release targets. The reason behind this is that the differences in packaging make it difficult for developers to debug applications built in this way. The first step to upgrading the project configuration is to add a template override from app to lib in the device-release configuration section:

TEMPLATE = app
TARGET = cascadescookbookqml

CONFIG += qt warn_on debug_and_release cascades10

INCLUDEPATH += ../src
SOURCES += ../src/*.cpp 
HEADERS += ../src/*.h 

device {
	CONFIG(release, debug|release) {		
		DESTDIR = o.le-v7
TEMPLATE=lib
QMAKE_CXXFLAGS += -fvisibility=hidden
	} 
	CONFIG(debug, debug|release) {
		DESTDIR = o.le-v7-g
	}
}

simulator {
	CONFIG(release, debug|release) {
		DESTDIR = o
	} 
	CONFIG(debug, debug|release) {
		DESTDIR = o-g
	}
}

OBJECTS_DIR = $${DESTDIR}/.obj
MOC_DIR = $${DESTDIR}/.moc
RCC_DIR = $${DESTDIR}/.rcc
UI_DIR = $${DESTDIR}/.ui

These changes switch the target from an executable to a library and hide the symbols to minimize the size.

The next thing that needs to change is the main.cpp file. Change the main() declaration as follows:

Q_DECL_EXPORT int main(int argc, char **argv)

The last step is to update the bar.descriptor.xml file as follows:

    <configuration id="com.qnx.qcc.toolChain.1485069140" name="Device-Debug">
       <platformArchitecture>armle-v7</platformArchitecture>
       <asset path="arm/o.le-v7-g/cascadescookbookqml" entry="true" type="Qnx/Elf">cascadescookbookqml</asset>
    </configuration>
    <configuration id="com.qnx.qcc.toolChain.1120265426" name="Device-Release">
       <platformArchitecture>armle-v7</platformArchitecture>
       <asset path="arm/o.le-v7/cascadescookbookqml" entry="true" type="Qnx/Elf">cascadescookbookqml</asset>
    </configuration>

Changes to:

    <configuration id="com.qnx.qcc.toolChain.1485069140" name="Device-Debug">
       <platformArchitecture>armle-v7</platformArchitecture>
       <asset path="arm/o.le-v7-g/cascadescookbookqml " entry="true" type="Qnx/Elf">HelloPhone</asset>
    </configuration>
    <configuration id="com.qnx.qcc.toolChain.1120265426" name="Device-Release">
       <entryPointType>Qnx/Cascades</entryPointType>
       <platformArchitecture>armle-v7</platformArchitecture>
       <asset path="arm/o.le-v7/cascadescookbookqml.so" entry="true" type="Qnx/Elf">libcascadescookbookqml.so</asset>
    </configuration>

After making these changes, export your project to a zip file. If you haven’t already done so, create a new workspace. Import the project into the new workspace, change the active build to Device-Release, and clean and rebuild the project. You should have a Cascades Cookbook sample app that starts up faster! My testing showed a reduction in start time from 1.96 seconds to 0.68 seconds. Feel free to convert all of your Cascades apps and spread the word!

About Alex Kinsella

Promoter of apps. Connoisseur of tacos. By day, I'm a PR and Social Media Manager at BlackBerry.

Join the conversation

Show comments Hide comments
+ -
blog comments powered by Disqus