What are the main key-points a Flex developer should remember in order to improve performance of Flex applications? The ones which come to my mind are:
- extending ItemRenderers from more lightweight base classes: i.e. UIComponent
- using suspendBackgroundProcessing set to true for animations
- using ArrayLists instead of ArrayCollections where appropriate.
- useVirtualLayout in Spark DataGroups (unfortunately this step requires Scrollers to make this advice effective)
- SQLight performance optimizations for AIR apps (transactions etc)
- Probably splitting long data processing into different frames? (Never done this though, so I might be mistaken)
What are the key guidelines you try to follow while developing your Flex3/Flex4/AIR applications in order to increase their performance?
My list:
P.S. Автор, а ты русский язык знаешь? :)
The main things I consider, in order of importance:
Binding
Creates a lot of extra code, and can cause a serious degradation in performance when bindings are not removed. For example, if you reuse components in an applications, listening functions are active throughout the entire flow of your application, consuming unnecessary memory and CPU cycles. For larger applications consider the BindingUtils class.
Note that you cannot unbind properties bound with curly braces
{myVariable}
Validate (invalidate) calls are some of the most expensive calls in Flex. Be careful when using them.
validateNow();
Understand the Flex component lifecycle. Overriding these methods can streamline the instantiation process.
Use Vector objects. More information.
Some more basic tips:
Do not use expensive operations in loops.
In the case of
massiveArray
, a very large array, length() might be an expensive operation. Assignvar massiveArrayLength:int = massiveArray.length;
to improve performance.http://jacksondunstan.com/ has a wealth of articles on optimizing your code. The man is a genius.
Avoid creating unnecessary variables, as instantiation is expensive. Always reuse variables if possible.
Instead, just return immediately.
If you have access to it, the Flash Profile perspective is your friend. It's a powerful profiler that can reduce the time involved in optimizing a codebase.
It seems to me a lot of people have performance issues w/ itemRenderers. So, my one contribution here to never use binding an itemRenderer. I fix a lot of customer "memory leak" bugs just by rewriting their itemRenderers to use the dataChange event instead of binding.
Beyond that, I second @Wade Mueller's comment about avoiding nested containers as much as possible.
Although this is less important with the lighter weight Spark Groups, I always try to keep the number of nested containers to a minimum and set explicit positions/sizes when possible. Complicated UIs with dynamically sized containers nested within one another cause a ton of (usually unnecessary) measuring to have to occur. This often results in huge lags when switching between views.