Flex性能调优相关的一些总结

时间:2023-03-09 04:39:48
Flex性能调优相关的一些总结

1.Performace包含4点:
(1)Latency反应时间(2)Scalability:可伸缩性(3)Reliablity:稳定性(4)Availability:可用性
2.运行时生命周期:
Flex只有两帧frames:Preload frame 和 application frame。
每一个flex application 是一个MovieClip,因为每个flex application都有SystemManager,他是继承自

flash.display.MovieClip.
Flex application的入口是Application layout的容器,他是继承自UIComponent。
UIComponent->Container->LayoutContainer->Application->WindowedApplication
3.典型的生命周期事件:

add:  组件被添加到容器上(addChild, addChildAt)时发出
preinitialize:  预初始化时发出
initialize:  完成构造,所有属性都被设置完成后发出
creationComplete:  完成构造,属性,测量,布局,绘制后发出
applicationComplete:  Dispatched after the Application has been initialized, processed by the LayoutManager,

and attached to the display list.

0:Application 1:inner Container 2:component

preinitializeHandler0 called!
childAddHandler0 called!
preinitializeHandler1 called!
initializeHandler1 called!
childAddHandler1 called!
preinitializeHandler2 called!
initializeHandler2 called!
initializeHandler0 called!
creationCompleteHandler2 called!
updateCompleteHandler2 called!
creationCompleteHandler1 called!
updateCompleteHandler1 called!
creationCompleteHandler0 called!
updateCompleteHandler0 called!

4.创建策略:
每个容器都有如下的创建策略:
all:创建所有的组件
auto:按照默认策略
none:不创建,直到调用createComponentFromDescriptors方法被调用
queued:首先创建所有的容器,然后把孩子依次创建,creationIndex决定初始化顺序,小者优先。

5.检测启动的时间
var recordedTime:Number = getTimer();

6.延迟和顺序创建组件

7.在flex Application中包含另外一个Application
<mx:SWFLoader source="FlexApp2.swf" />
我们经常要把一个swf包含进来,并且调用它的方法。当一个swf被包含进来后,就可以了。SWFLoader有以下几个事件
complete,init,progress,unload。
(1)各自隔离 var loaderContext:LoaderContext;
loaderContext.applicationDomain = new ApplicationDomain();
(2)子域var loaderContext:LoaderContext;
loaderContext.applicationDomain =new ApplicationDomain(ApplicationDomain.currentDomain);
(3)同一个域 var loaderContext:LoaderContext;
loaderContext.applicationDomain = ApplicationDomain.currentDomain;

8.RSL(Run-time Shared Libraries)
RSL是在Application之外的一个库,这个库只下载一次,可以被多个Application公用。
好处:(1)Application的size变小了(2)只下载一次节约时间
RSL有两种link方式(1)staic linking所有的类都被打到同一个包中,这样快,但是swf会很大。(2)dynamic linking,额

外的类被打到一格swf中,在运行时链接。
RSL分为3类:(1)Standard RSL同一个domain中多个Applications公用(2)Cross-domain RSL跨域公用(3)Framework RSLs

:Flex框架本身的rsl。
standard rsl和cross-domain rsl存在于浏览器的缓存中,而framework rsl存在于flashplayer的缓存中。

9.更好的应用设计

10.高效的使用容器。
每一个新的容器都包含计算位置,大小和样式。动态计算则需要更多的工作量。

11.使用绑定还是事件?

12.Array还是ArrayCollection

13.利用延迟加载

14.内存使用,抗压性,可用性
flash.system.System.totalMemory

Doing the following is beneficial:
Stop other heavy processes on your machine.
Avoid using debug on the Flash Player.
Switch the trace and logging options off.
Switch any hardware or operating system–level factors that affect memory allocation to the
Flash Player.