There are three factors that affect overall startup time: compilation time, download time, and application initialization time. Since compilation time only affects the first request and downloaded content is cached after the first request the application initialization time affects the users experience most of all. There are a few simple steps you can take to analyze the initialization time and target the areas that are affecting performance most.
With a few lines of code you can see the amount of time it takes to initialize your application.
- First you will need to add a Label component in some unobtrusive area of your application. In this example we will call it "initLbl"
<mx:Label id="timerLbl"/>
- Add the following attribute to your Application tag: creationComplete="doLater(this, 'updateLabel')"
<mx:Application ... creationComplete="doLater(this, 'updateLabel')">
- Add the following function to your Application script:
function updateLabel
<mx:Script>
<![CDATA[
{
timerLbl.text = getTimer();
} ]]>
</mx:Script>
- Run your Flex application. The label should display the number of milliseconds that elapse during application startup. Run twice more to get an average.
- Now you can start to gradually remove pieces of your application, until you've whittled it down to nothing. Each time that you remove a piece, run the app (three times) and record the startup time. Due to dependencies in your code you may not be able to remove the pieces entirely. You can wrap your code snippets with the following code to prevent it from initializing when the application starts.
<mx:Canvas creationPolicy="none">...tag(s) to be removed...</mx:Canvas>
After identifying code that is causing the problem you can use the recommendations in the performance developer center article to reduce the intitialization time of your application. You can also use the Flex Profiler to do more in depth analysis but the above approach provides developers a simple way to profile their application. Thanks to David George from Flex Engineering for providing the steps.
There are no comments on this entry.