20 x tips to better optimize your flash content @eladelrom

Click here to load reader

Post on 16-Dec-2015

213 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • Slide 1
  • 20 x Tips to better Optimize your Flash content @EladElrom
  • Slide 2
  • #1: Flash Player 10.1 out of the box optimization Instance Management Screensaver Mode NativeApplication.nativeApplication.systemI dleMode = SystemIdleMode.KEEP_AWAKE; GPU Hardware Acceleration
  • Slide 3
  • #2: Profiling ur App Flash Benchmark 8: http://www.kongregate.com/games/SnailsAnimation/flash-benchmark-08 or http://www.timo-ernst.net/misc/riabench-start/ http://www.kongregate.com/games/SnailsAnimation/flash-benchmark-08http://www.timo-ernst.net/misc/riabench-start/ Flash Builder Profiler Profiling with System Tools Grant Skinners Benchmark AS3 FlexUnit 4.1 Benchmark FrameStats - Monitor Frame Rate Open Source Profiler - http://jpauclair.net/flashpreloadprofiler/
  • Slide 4
  • #2: Profiling ur App OHHH. I almost forgot!!! you can just do: getSize to find out the memory size of an object
  • Slide 5
  • #3: Architecting Micro-architecture frameworks?
  • Slide 6
  • Tip #4: I/O AMF, RTMP. Use James Wards tool to benchmark and see the memory difference: http://www.jamesward.com/census/. http://www.jamesward.com/census/ Use lazy loading whenever possible. Strong type the data with AMF on client and server side to increase performance.
  • Slide 7
  • Tip #5: Manipulating swf Framerate Reducing fps when your app is inactive Increase the fps once the app is active again Increase fps while animation is playing to create a more smooth experience and keeping a stack of all the animations being played to know when we can drop the fps. Provide a cross platform API (Pure AS3, Flex, AIR) https://github.com/EladElrom/Flash-Optimizing-Tools framerateManager:FrameRateOptimizer = new FrameRateOptimizer( this, true );
  • Slide 8
  • Tip #6: Reduce memory usage Memory leaks due to listeners that have been set by us or someone else and never removed from memory: Solution: Listeners API movieClip.addEventListener( listeners.type = MouseEvent.CLICK, listeners.handler = onClick ); movieClip.addEventListener( listeners.type = MouseEvent.DOUBLE_CLICK, listeners.handler = onDoubleClick ); listeners.removeAllListeners( movieClip );
  • Slide 9
  • Tip #7: Avoid memory leaks Call gc twice, or in AIR system.gc(): Ensure GC will do his job correctly: Set weekly references - where possible: addEventListeners and Dictionary classes. Dont keep references - nulling objects with events dont unhook them.
  • Slide 10
  • Tip #8: Update screen once per frame Elastic Racetrack Frame starts - Event.ENTER_FRAME Frame actions executed - Event.FRAME_CONSTRUCTED End of Frame cycle - Event.EXIT_FRAME Pre-render phase starts - Event.RENDER Final user code is executed Player renders changes to display Cycle completed Avoid using updateAfterEvent, since it interrupt the Player and increases the player work load. Handle invalidation on your own using the stage.invalidate() property
  • Slide 11
  • Tip #9: Decrease nesting
  • Slide 12
  • Tip #10: Reduce complexity Shape Constructor code of children executed: 276 Sprite Constructor code of children executed: 399 UIComponent Constructor code of children executed: 1078 Group Constructor code of children executed: 1195 Use low level classes such as TextField, SimpleButton (when possible) over halo and Spark. It will require more coding but will improve performance. Avoid using TLF - when possible. Use Halo components over Spark components. When creating custom components use Sprite over MovieClip and UIComponent over Group When creating graphics its recommended to use Shape display object. TextField Constructor code of children executed: 68 Player renders changes display list: 168 mx:Text Constructor code of children executed: 743 Player renders changes display list: 685 s:Label Constructor code of children executed: 1136 Player renders changes display list: 198 s:RichText Constructor code of children executed: 416 Player renders changes display list: 3224
  • Slide 13
  • Tip #11: Avoid expensive operations Bitmap filters and perspective distortion Frequently-updated Text
  • Slide 14
  • Tip #12: Decreasing execution time Primitives vs generic object Typing over generic objects Loops Array vs ByteArray vs Vector Callbacks and events Regex and search string Databinding Sealed vs. dynamic classes if...else statements Use strict mode Flex related tips Use e4x with caution Increasing rendering speed Manual cache as BitmapData or Bitmap Cache as bitmap matrix Set all children caching policy Check the status of all children
  • Slide 15
  • Tip #13: Avoiding initializing and reference to unused classes
  • Slide 16
  • Tip #14: Set redraw region to min
  • Slide 17
  • Tip #15: Reducing swf file size Limit font unicode-range Implement RSL in your project - Runtime Shared Libraries Load assets on runtime and reduce assets file size Export Release Build Using strict mode
  • Slide 18
  • #16: Use Tools to reduce swf file size Apparat SWF Optimizer
  • Slide 19
  • Tip #17: Splitting apps into modules
  • Slide 20
  • Tip #18: Reuse objects - Object pooling
  • Slide 21
  • Tip #19: Working with external assets caching data in the memory cache data on the local device Image blitting
  • Slide 22
  • #20: be poactive & keep optimizing Be Proactive: take into account benchmark and memory usage when writing your code. Write code first: create your application and after its running, take time to optimize.
  • Slide 23
  • Q&A http://insideria.com/2010/11/flash-player- 101-mobile-optimi.html http://insideria.com/2010/11/flash-player- 101-mobile-optimi.html http://insideria.com/2010/11/optimize- flash-content-and-imp.html http://insideria.com/2010/11/optimize- flash-content-and-imp.html http://elromdesign.com/blog @EladElrom
  • Slide 24
  • 24