Summary of common methods for flex Performance Optimization

Source: Internet
Author: User

As we all know, broadband applications in China are not as developed as in many developed countries. The bandwidth of individual applications is generally below 2 MB, how to make your flex application run smoothly on the client becomes a problem that restricts the development of each flex Application Program Major problems of members.
Here, I have collected and sorted out some experiences on the Internet.

Basic Principles:
1. Load media from the outside)
Heider mentioned a common flex best practice-limiting the number of media embedded into an application/SWF file. resources such as videos and MP3 files can be loaded from external SWF files.
The flex framework can directly compile images, MP3 files, fonts, and other resources into SWF. This method can be used when you want end users to get all the resources, but it will cause your application to stay in the "loading" phase for a long time.

2. Restrict character sets in embedded fonts
Heider recommends limiting character sets in embedded fonts to reduce the total download time of SWF files:
When you embed a font in flex, you will get support for all characters in the font. Although this may be what you want, are you sure you want all the characters? For example, in an English-only application, are you sure you want to take the time to download Chinese character data?
3. cache framework
Heider reviews Flex 3 Support for runtime-shared-libraries (RSL)Article:

from Flex 3, You Can cache the Adobe signature framework-RSLs to the cache of Flash Player. There are two benefits. First, the Framework RSLs of the signature cached in the Flash Player cache can be shared by all configured flex applications. In other words, if someone's application has downloaded the K signature framework RSL and the RSL is still in the Flash Player cache, then your application can use the cached RSL. Second, even if someone clears the browser cache, there is no impact on the Flash Player cache.
4. consider modularization
Heider talked about the benefits of dividing flex applications into modules: Another way to reduce the font loading time is to divide your flex applications into modules. One advantage of using a module is that you can fully control it when loading and detaching a module.
the last reason for dividing modules into modules is that they are faster and I can load them instantly. In other words, the only module to be loaded at startup is the step1.swf module. Therefore, when a module is used, the end user saves start time, but it takes more time to switch from one module to another, because each module must be loaded in JIT format. In my applications, it takes more time to switch between steps 1-5 for the first time.
5. Deferred instantiation
Heider provides many suggestions around the "creationpolicy" attribute of the Flex component and the different parts about when to instantiate the application.
if you want to reduce the total time available for downloading data to users, it is imperative to postpone instantiation. The idea behind this technology is to create objects in the memory until the application is actually used.
although the delayed instantiation technology may cause a little-usually less-obvious-latency throughout the application's use process, compared with the long start delay, it is acceptable. Another benefit of deferred instantiation is the optimization of memory usage.

The above principle comes from Jun Heider's excellent article published on the insideria site of O 'Reilly. This article provides many suggestions on how to speed up the startup of flex applications, to help you reduce the time when you see the annoying "loading" dialog box. He discussed different aspects of the problem in depth and judged the advantages and disadvantages of each technology. Heider also talked about an "experimental" term-"Use stream", which he talked about when discussing Dirk eismann's post (building monolithic flex SWFs that still startup quickly. Eismann proposed a technology to use multiple frames in Flash Player to achieve stream in some applications. View all the posts to learn more about the technology and suggestions on accelerating flex startup.

Memory release optimization principles
1. All references of the deleted object must be deleted to be disposed of as garbage collection by the system;
2. If the child object inside the parent object is referenced by other external objects, the child object will not be deleted, and the child object will not be deleted;
3. If an object references an external object, you must remember to set the reference of this object to null when you are deleted or do not need to use this reference object;
4. The reason why this object cannot be deleted may not be because it has been referenced by itself. It may also be because the child has been referenced by external entities and cannot be deleted by the father;
5. In addition to references that need to be deleted, system components, global tools, and management classes must call the detach method to delete internal objects. Otherwise, memory leakage and performance loss may occur;
6. If the parent object is deleted immediately, it does not mean that the child object will be deleted or immediately deleted. It may be deleted after being automatically deleted by the system or during the second removal operation;
7. If the parent object does not clear references to the child object after removing the child object, the child object cannot be deleted, and the parent object cannot be deleted;
8. if the registered event is not removed, it does not affect the custom forced collection mechanism, but it may affect the normal collection mechanism. Therefore, it is best to ensure that all registered event listeners should be deleted.
9. If the parent object is deleted, it does not mean that all other sub-objects are deleted. A state of leakage is found. Code If it is not the same as other States, no leakage will occur. test and analysis should be performed one by one for each module until the entire object can be deleted in any State of the test.
Example of Memory leakage:
1. Reference leakage: this refers to the reference of the Child object. The external references to this object or sub-object must be set to NULL;
2. system class leakage: You forgot to delete the system class, such as bindingutils. bindsetter (), changewatcher. after the Watch () function is complete, you need to call changewatcher. the unwatch () function clears references. Otherwise, the objects using this function will not be deleted;
Similarly, there are music, video, image, timer, event, binding, and so on.
3. effect leakage: when the effect of effect is applied to the component, when the object is deleted, the effect animation on the object and the sub-object needs to be stopped, and then the target object of effect is set to NULL; if you directly set effect to null without stopping the animation, the object cannot be removed normally.
4. SWF leakage: to completely delete a SWF, call its unload () method and set the object to NULL;
5. Image leakage: After the image object is used, set source to null (for testing );
6. sound and video leakage: if you do not need a music or video, you need to stop the music, delete the object, and set the reference to null;
Memory leakage solution:
1. Perform garbage processing in the removed_from_stage event return of the component (remove all external references (both vo and components need to be deleted), delete the listener, and call the clearing method of the system class)
Remove and then set null to make sure that all objects after being removed or removeall are released in the external reference;
2. use the flex performance optimization tool profile to monitor the project process. You can know which objects have been created in history, which objects have not been deleted, and the number of created objects, memory usage, creation process, and other information;
Conclusion: The key is to clear the file, remember to delete the reference you set, and remember to recycle the system classes you used. If the preceding problem is solved, the user-defined forced recycler may be automatically reclaimed by the system normally.

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.