Upload
ilmyar
View
222
Download
0
Embed Size (px)
Citation preview
8/6/2019 AS3Perfr
1/17
2006 Adobe Systems Incorporated. All Rights Reserved.1
ActionScript 3
Performance
Tuning
Ted Patrick
Flex Evangelist
Adobe Systems
8/6/2019 AS3Perfr
2/17
2006 Adobe Systems Incorporated. All Rights Reserved.2
Overview
Premature Optimization How Flash Player and ActionScript work
Strong Typing - variables, events, return types
Measuring Performance
8/6/2019 AS3Perfr
3/17
2006 Adobe Systems Incorporated. All Rights Reserved.3
Premature Optimization
More Computing sins are committed in the name of eciencythan any other reason including blind stupidity W.A. Wulf
Premature Optimization is the root of all evil. - Hoare and Knuth
Bottlenecks occur in surprising places, so dont try to second
guess and put in a speed hack until you have proven thats
where the bottleneck is. - Rob Pike
8/6/2019 AS3Perfr
4/17
2006 Adobe Systems Incorporated. All Rights Reserved.4
How Flash Player works
Graphics
Rendering
ActionScript
Execution
ActionScript
Frame & Network
Events
One Frame Cycle
8/6/2019 AS3Perfr
5/17
2006 Adobe Systems Incorporated. All Rights Reserved.5
AVM2 Architecture
8/6/2019 AS3Perfr
6/17
2006 Adobe Systems Incorporated. All Rights Reserved.6
How Flash Player works
Flash Player presents a single thread of execution Flash Player is multi-threaded!!!
Rendering and ActionScript are executed sequentially.
The player will do everything you ask it to do.
Do to much in one frame cycle a script-timeout occurs.
Defer AS execution to next frame cycle with:
mx.core.UIComponent.callLater()
8/6/2019 AS3Perfr
7/17
2006 Adobe Systems Incorporated. All Rights Reserved.7
Typing optimizes bytecode!
Typing optimizes bytecode!
Typing optimizes bytecode!Typing optimizes bytecode!
8/6/2019 AS3Perfr
8/17
2006 Adobe Systems Incorporated. All Rights Reserved.8
Typing optimizes bytecode!
Typing aects member access. Two Performance Cases for member access
Strong references are equivalent to C++ member access
Must use dot operator for member
Must use strong typing
Weak references are a hash lookup
No typing
Use of [member] access
8/6/2019 AS3Perfr
9/17
2006 Adobe Systems Incorporated. All Rights Reserved. 9
Member Access Examples
instance.x
instance[3]
This stuhappens a lot!!!
8/6/2019 AS3Perfr
10/17
2006 Adobe Systems Incorporated. All Rights Reserved. 10
Typing Examples
function a ( o ) // RETURN WEAK
{
return o; // WEAK
}
function b ( o ) // RETURN WEAK{
return o.x; // WEAK
}
function c ( o:Object ) // RETURN WEAK
{
return o.x; // WEAK
}
8/6/2019 AS3Perfr
11/17
2006 Adobe Systems Incorporated. All Rights Reserved. 11
Typing Examples
class Base extends Object { var x:int; // STRONG
var y:int; // STRONG
var z; // WEAK
}
function a ( o:Base ) // RETURN WEAK{
return o.z; // WEAK
}
function b ( o:Base ):int // RETURN STRONG
{ return o.x; // STRONG
}
8/6/2019 AS3Perfr
12/17
2006 Adobe Systems Incorporated. All Rights Reserved. 12
Typing Examples
dynamic class Base extends Object {
var x:int; // STRONG
var y:int; // STRONG
}
function a ( o:Base ) // RETURN WEAK
{
return o.z; // WEAK
}
function a ( o:Base ):int // RETURN STRONG
{
return o.x; // STRONG
}
8/6/2019 AS3Perfr
13/17
2006 Adobe Systems Incorporated. All Rights Reserved. 13
Typing Examples
dynamic class Base extends Object { var x:int; // STRONG
}
class Example extends Base {
var z:int //STRONG
}
function a ( o:Example ):int // RETURN STRONG
{
return o.y; // WEAK
}
function a ( o:Example ):int // RETURN STRONG{
return o.x; // STRONG
}
8/6/2019 AS3Perfr
14/17
2006 Adobe Systems Incorporated. All Rights Reserved. 14
Array Member Access
Arrays include fast path for dense portion
Member access is as fast as C++ in dense portion
var a:Array = [1,2,3,4,5];
a[1000] = 2010;
a[1001] = 2011;
a[2]; //FAST PATH
a[1000]; //SLOW PATH
Demo
8/6/2019 AS3Perfr
15/17
2006 Adobe Systems Incorporated. All Rights Reserved. 15
Typing with int, uint, Number
Avoid implicit type conversion Math operations can induce type conversion
Sometimes just using Number is more ecient.
8/6/2019 AS3Perfr
16/17
2006 Adobe Systems Incorporated. All Rights Reserved. 16
Strong Typing improves productivity
Simpli
ed debugging Compiler will throw compile-time errors
Code hinting in Flex Builder is based on Strong Typing
8/6/2019 AS3Perfr
17/17
2006 Adobe Systems Incorporated. All Rights Reserved. 17
Contact Info
Ted PatrickFlex Evangelist
http://www.onex.org