Performance Tuning for Flex applications

Source: Internet
Author: User
Tags event listener throw exception

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.