A summary of common techniques for Flex performance optimization _flex

Source: Internet
Author: User
Tags garbage collection memory usage browser cache
As we all know, the current domestic broadband applications are not as developed in many developed countries, the personal application of bandwidth is basically 2M below, how to make your flex application can smooth running in the client's problem, become a constraint on each Flex application development Programmer's big problem.
Here, I collect and tidy up the network on this aspect of experience, welcome everyone to add.

Basic principles:
1. Load media from outside
Heider mentions a common flex best practice--limiting the number of media embedded in an application/swf file, such as images, movies, and MP3, can be loaded from an external SWF file.
The flex framework can directly compile resources such as pictures, MP3, and fonts into SWF. This approach can actually be useful when you want the end user to have all the resources, but it can cause your application to stay in the "Loading" phase for a long time.

2. Restricting character sets in embedded fonts
Heider recommends restricting the character set in embedded fonts to reduce the total download time for SWF files:
When you embed a font in flex, you get support for all the characters in that font. Although this may be what you want, but are you sure you need all the characters? For example, in an English-only application, are you sure you really want to take the time to download the Chinese character data?
3. Caching framework
Heider reviews the Flex 3 support for Runtime-shared-libraries (RSL) article:

Starting with Flex 3, you can cache the adobe signed frame--rsls to Flash Player's cache. This has two advantages. First, a framework RSLs that is slow to exist in Flash Player cache can be shared by all of the configured flex applications. In other words, if someone's application has downloaded the 500k signed frame RSL, and the RSL is still in Flash Player cache, then your application can use the cached RSL. Second, even if someone clears their browser cache, it has no effect on flash Player cache.
4. Consideration of modularity
Heider talked about the benefits of dividing flex applications into modules: Another way to reduce font load time is to divide your flex application into modules. One advantage of using a module is that you can completely manipulate it when loading and unloading modules.
The last reason to divide into modules is that they are faster and I can load them instantly. In other words, the only module that needs to be loaded at startup is the step1.swf module. Thus, in the case of using a module, the end user saves the startup time, but it takes more time to switch from one module to another, because each module needs to be loaded in a JIT fashion. In my application, it takes more time for the user to switch between steps 1-5 for the first time.
5. Postponement of the instantiation
Heider gives a lot of advice around the "Creationpolicy" attribute of the flex component and when the different parts of the application are instantiated.
If you want to reduce the total time it will take to download from the data to the user's real use, it is imperative to postpone the instantiation. The idea behind this technique is to create objects in memory until the application is actually used.
Although the postponement of the instantiation technique results in a slight-usually less obvious-delay throughout the application's use, it is acceptable compared to the long startup latency. Another benefit of deferred instantiation is the optimization of memory usage.

The above principles come from June Heider on O ' Reilly's Insideria site, which gives a lot of advice on how to speed up the startup speed of flex applications to help reduce the time it takes to see a nasty "Loading" dialog box. He delves into the different aspects of the problem and judges the strengths and weaknesses of each technique. Heider also talked about an "experimental" clause-"use stream," a post he was discussing Dirk Eismann (building monolithic Flex SWFs that still startup quickly.) ) was mentioned. Eismann proposes a technique to take advantage of multiple frames in Flash Player to achieve the purpose of streaming in a partial application. View all posts to learn more about the technology and suggestions for speeding up the flex start speed.

Memory Release Optimization principles
1. All references in the external to the deleted object must be removed cleanly to be disposed of by the system as garbage collection;
2. The child objects inside the parent object are referenced by other external objects, causing the child object to not be deleted and the child object not being deleted, causing the parent object to not be deleted;
3. If an object references an external object, it is important to remember to set this object's reference to NULL when it is deleted or if you do not need to use the reference object;
4. This object can not delete the reason is not necessarily that they have been cited, but also may be their children are outside the reference, the child can not delete the father also deleted;
5. In addition to the need to delete the reference, system components or global tools, management classes, if the uninstall method provided by the need to invoke the deletion of internal objects, otherwise it may cause memory leaks and performance loss;
6. The parent object is deleted immediately, not on behalf of the child object will be deleted or immediately deleted, may be in the late by the system automatically deleted or the second removal of the operation was deleted;
7. If the parent object removes a child object and does not clear a reference to the child object, it cannot be deleted, and the parent object cannot be deleted;
8. Registered Events if not removed does not affect the custom forced collection mechanism, but may affect the normal recycling mechanism, so it is best to do registered event listeners should remember to remove clean.
9. The parent object is deleted does not mean that the rest of the child objects have been deleted, to find a state of the leak code is not equal to other states are not disclosed, to each module of the state of the test and analysis, until the test in any state can delete the entire object.
Memory leaks For example:
1. Reference disclosure: A reference to a child object that needs to be null for external references to this object or to children;
2. System class Leakage: using the system class and forget to do delete operations, such as Bindingutils.bindsetter (), Changewatcher.watch () function after the completion of the call to Changewatcher.unwatch () function to clear the reference, otherwise the object using this function will not be deleted;
There are similar music,video,image,timer,event,binding and so on.
3. Effect leakage: When the application of the effect of the component effect, when this object is deleted, the object and the effect animation on the child to stop, and then put the effect target object null; If you do not stop the animation directly put the effect null will not be able to remove the object normally.
4. swf disclosure: To completely delete a SWF to invoke its unload () method and set the object null;
5. Picture leakage: When the image object is used, the source should be null;
6. Sound, video leakage: When you do not need a music or video is needed to stop music, delete objects, reference null;
Memory Leak resolution:
1. Do garbage handling in component Removed_from_stage event (remove all external references (both VO and component need to be removed), remove listener, call System class Cleanup method)
Remove and then reset NULL to ensure that the object removed or RemoveAll after the external reference all released clean;
2. Using Flex's performance Optimization tool profile to monitor the project process, you can know what objects history has created, what objects are not being deleted, the number of created, the amount of memory consumed, and the process of creating information;
Summary: The key or to do a good job of cleaning up their own set of references to remember to delete, their own use of the system class to remember to do a good job of recycling processing. The above problem solved good words do not need to custom force collector also may be automatically recycled by the system.

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.