As we all know, flex applications have more or less performance problems. Especially enterprise-Class large number of applications, the usual solution is to load the module, time-sharing load data and other measures to solve. Now let's talk about code-level optimization:
1. Minimize the unnecessary operation of the procedure. There are two types of expressions:
var a:unit = B + (1024-200)/2;
var a:unit = b+412;
Obviously the expression below is faster.
2. Use multiplication as much as possible in place of division operations. The following two expressions:
result = NUM/4;
REUSLT = num * 0.25;
By means of statistical tools, multiplication can save 150ms of time compared to division.
3. Use strong types whenever possible. Like what:
var pt:object = {X:x,y:y};
var pt:point = new Point (x,y);
4. Use an implicit type conversion. Like what
var pt:point = points[i] as point;
var pt:point = points[i];
The second expression uses an implicit type conversion, which saves overhead.
5. Casting is sometimes more useful than converting with AS. Such as:
PT = points[(i*2) as unit];
PT = Points[uint (i*2)];
6. Set the precedence of the conditional expression. Such as:
if (Expensivetest () && usuallyfalse)
if (Usuallyfalse && expensivetest ())
When you are with an operation, you should place an expression that is false in most cases to the front (as in the second expression).
The loop condition value in a 7.for loop statement should be a fixed value. Such as:
for (var i=0; i<arr.length; i++)
for (var i=0; i<l; i++)
The second method should be used to store the length attribute value of the arr in a variable.
8. Callback events are faster than events that are distributed separately, and are faster than bubbling events.
9. Minimize the use of Try...catch to throw exception information. Such as:
try {isnull.x = 3;} catch (e:*) {}
if (isNull) {isnull.x = 3;}
Use the second method to reduce the number of exceptions.
10. Use the RemoveEventListener method to clear the idle event listener.