The document discusses common optimizations for ActionScript 3 code. It provides guidelines for optimization, including avoiding optimization early in development, as some optimizations may not be noticeable to users. It also recommends avoiding filters and motion where possible. The document then provides tips for optimizations like using bitmaps, conserving memory through object type choices, reusing objects, letting the garbage collector free memory, activating and deactivating objects, and disabling mouse interactions. It is presented by Teerasej Jiraphatchandej, the user group manager of the Thai Adobe Developer Community.
1. ACTIONSCRIPT 3:
COMMON OPTIMIZATION
Teerasej Jiraphatchandej
User Group Manager, Thai Adobe Developer Community
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
2. Understand:
CODE
EXECUTION
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
3. CODE EXECUTION
24 fps
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
4. CODE EXECUTION
• Phase 1: event & enter frame
• Phase 2: rendering
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
5. CODE EXECUTION
Phase 1 Phase 2
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
6. CODE EXECUTION
Phase 1 Phase 2
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
7. CODE EXECUTION
Phase 1 Phase 2
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
8. CODE EXECUTION
Phase 1 Phase 2
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
9. CODE EXECUTION
< 24 fps
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
10. Guideline:
OPTIMIZATION
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
11. Create by Teerasej Jiraphatchandej.
AVOID OPTIMIZATION EARLY
All rights reserved .
Thai Adobe Developer Community .
http://thaiadc.groups.adobe.com
http://www.flickr.com/photos/23912215@N02/4112230589/
12. Create by Teerasej Jiraphatchandej.
SOME OPS, NOT NOTICEABLE
All rights reserved .
Thai Adobe Developer Community .
http://thaiadc.groups.adobe.com
6264966_82f69fd170_b.jpg from flickr
13. Create by Teerasej Jiraphatchandej.
OPTIMIZED IS HARD MAINTAIN
All rights reserved .
Thai Adobe Developer Community .
http://thaiadc.groups.adobe.com
http://www.flickr.com/photos/nigelmeng/636115602/
14. Create by Teerasej Jiraphatchandej.
DON’T USE FILTER
All rights reserved .
Thai Adobe Developer Community .
http://thaiadc.groups.adobe.com
http://www.flickr.com/photos/kwerfeldein/1693519458/
15. Create by Teerasej Jiraphatchandej.
AVOID MOTION
All rights reserved .
Thai Adobe Developer Community .
http://thaiadc.groups.adobe.com
http://www.flickr.com/photos/saxonmoseley/106432807/
16. Create by Teerasej Jiraphatchandej.
PERFORMANCE TEST
All rights reserved .
Thai Adobe Developer Community .
http://thaiadc.groups.adobe.com
1717925528_1aba213644_o.jpg from flickr
17. Tips 1:
USE
BITMAP
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
18. FLASH CS6 BITMAP
• Normal
• Cache as Bitmap
• Export as Bitmap
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
19. CACHE AS BITMAP
• Possible use more memory than vector.
• Apply to each graphic, not animated movie clip.
• Don’t use with container that has animating children
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
20. EXPORT AS BITMAP
• Good for static object
• Increase SWF file size.
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
21. Tips 2:
CONSERVING
MEMORY
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
22. DISPLAY OBJECT TYPE
• Shape
• Sprite
• MovieClip
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
23. SHAPE
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
24. SPRITE
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
25. MOVIE CLIP
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
26. PRIMITIVE
• Around 4 - 8 KB
• String depend on used
• Can’t optimize more
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
27. Tips 3:
REUSING
OBJECT
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
28. REUSING OBJECT
for ( ... ) {
var a : Object = new ...
}
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
29. REUSING OBJECT
var a:Object;
for ( ... ) {
a = new ...
}
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
30. Tips 4:
FREE MEMORY
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
31. GARBAGE COLLECTOR
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
32. GARBAGE COLLECTOR
Stage
MovieClip
MovieClip
MovieClip
MovieClip
MovieClip
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
33. GARBAGE COLLECTOR
Stage
MovieClip
GC MovieClip
MovieClip
MovieClip
MovieClip
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
34. FORCE GC TO WORK
• remove all reference to object
• Remove event listener
• Set object to null
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
35. FORCE GC TO WORK
obj.removeEventListener();
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
36. BEWARE!!
• Set object to null, not force GC to run immediately
• GC use CPU and memory in running.
• Adobe AIR force GC using: System.GC();
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
37. Tips 5:
DEACTIVATE
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
38. ACTIVATE AND DEACTIVATE
• Object that removed from stage, doesn’t be destroyed
immediately
• Use framework to optimize performance
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
39. FORCE GC TO WORK
Event.ADD_TO_STAGE
EVENT.REMOVE_FROM_STAGE
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
40. Tips 6:
DISABLE
MOUSE
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
41. DISABLE MOUSE
• obj.mouseEnable = false;
• obj.mouseChildren = false;
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
42. GUIDELINE SUMMARY
• Don’t optimize too early
• Some optimization will not be noticeable by user
• Don’t use filter
• Avoid motion
• Do performance test
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com
43. TIPS SUMMARY
• Use BitMap
• Conserving memory
• Reusing object
• Free memory
• Activate & Deactivate
• Disable Mouse
Create by Teerasej Jiraphatchandej.
All rights reserved . Thai Adobe Developer Community . http://thaiadc.groups.adobe.com