Flash performance tuning (EN)
Upcoming SlideShare
Loading in...5
×
 

Flash performance tuning (EN)

on

  • 49,218 views

English version of CEDEC Flash performance tuning presentation ...

English version of CEDEC Flash performance tuning presentation
Note: what these slides refer to as "Project Monocle" has now been released, and is called Adobe Scout ( http://gaming.adobe.com/technologies/scout/ )

Statistics

Views

Total Views
49,218
Views on SlideShare
11,776
Embed Views
37,442

Actions

Likes
34
Downloads
245
Comments
2

45 Embeds 37,442

http://www.leebrimelow.com 33219
http://www.scoop.it 1724
http://khaledgarbaya.net 1002
http://www.khaledgarbaya.net 332
http://abauchu.net 294
http://goflash.collected.info 197
http://richinternetapplication.collected.info 176
http://blog.hansune.com 82
https://twitter.com 82
http://blog.kaizimmer.com 50
http://newsflash.collected.info 40
http://www.webpeace.net 37
http://www-ig-opensocial.googleusercontent.com 34
http://feeds.feedburner.com 28
http://geekoutsummer.wordpress.com 22
https://si0.twimg.com 17
http://devcafe.nhncorp.com 17
http://translate.googleusercontent.com 14
http://www.abauchu.net 13
http://www.hanrss.com 12
http://www.plurk.com 6
http://pinterest.com 5
http://webcache.googleusercontent.com 5
http://webpeace.net 5
http://localhost 3
http://dyingflash.com 3
http://cafe.naver.com 2
http://mx1.leebrimelow.com 2
http://m.leebrimelow.com 2
http://www.newsblur.com 2
http://hsmaker.com 1
http://flavors.me 1
https://twimg0-a.akamaihd.net 1
http://ranksit.com 1
http://10.100.0.241 1
http://edit.optimizely.com 1
http://127.0.0.1 1
http://tweetedtimes.com 1
http://www.systranet.com 1
http://www.leebrimelow.com.us6.hshh.org 1
http://131.253.14.66 1
http://2fwww.leebrimelow.com 1
http://192.168.35.49 1
http://lwww.leebrimelow.com 1
http://twitter.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Flash performance tuning (EN) Flash performance tuning (EN) Presentation Transcript

  • 60fps or Bust! Flash Game Performance Tuning from A to Z Andy Hall Adobe Japan© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Andy Hall アンディ ホール Game Evangelist ゲームエバンジェリスト Adobe Japan アドビ システムズ 株式会社 @fenomas© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Agenda • Overview • Tuning ActionScript 3.0 • Flash Player Internals • Rendering Optimization • Upcoming topics© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Principles of Optimization “Premature optimization is the root of all evil” Donald Knuth (早すぎる最適化は諸悪の根源)© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Optimization Flow Build for Architect for Optimize! speed and performance (only the slow parts) correctness© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Metrics To optimize you need measurable metrics! • FPS • Memory usage • CPU usage • Bandwidth? • Battery usage? • etc...© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Profiling Now: Soon: Flash Builder 4.6 Profiler Codename “Monocle”© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • TUNING ACTIONSCRIPT© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Tuning ActionScript 3.0 Caveats: • Often not as important as rendering • Beware of low-impact “tips and tricks”© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • The Basics • Always use AS3.0 Always! • Type everything • Prefer Vector.<type> over Array or Dictionary Only in • Prefer String methods over RegExp critical areas • Be careful with E4X and XML ( ) • Callbacks are faster than Event© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Pooling Instantiation can be expensive! Pool or reuse objects to avoid the cost of frequent creation and collection • Static temps • Object pooling© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Function Calls Function calls can be expensive too. Keep a shallow call stack and avoid recursion:© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Garbage Collections Know your GC! • Flash’s GC does both reference counting and mark-sweep. (If you want to tune memory usage, you need to understand these!) • Use Monocle to find if GC is firing too often • Pooling/reuse makes GC collection less frequent • For large collections, prefer literals (String, int..) or plain objects over complex objects (Sprite, Rectangle..)© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Smart GC Tell Flash when to trigger a GC! Call this between levels, when the game pauses, etc. Flash’s GC marks incrementally, and this command tells it to finish marking and do a collection if a GC was already imminent. The argument specifies how long you’re willing to wait for a GC: imminence=0.99; // GC if ready now imminence=0.01; // GC even if you need to pause a while© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • FLASH INTERNALS© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • The big picture // Flash’s internal loop (simplified) while() { sleep until (nextEvent OR externalEvent) if ( various events pending ) { handleEvents(); // handles Timer events, // fills audio/video buffers } if ( time for next SWF frame ) { parseSWFFrame(); executeActionScript(); } if ( screen needs update ) { updateScreen(); } }© 2012 Adobe Systems Incorporated. All Rights Reserved. Gory details: http://blog.kaourantin.net/?p=82
  • Flash’s Internal Loop Handle Next SWF frame various Rendering events Execute scripts sleep© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Point: Because of this, most recurring scripts should be handled in Event.ENTER_FRAME ! ENTER_FRAME Handle Next SWF frame external Rendering events Execute scripts sleep© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • The Display List Vector shapes Video Bitmap Display List© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Dirty Rectangles “Dirty” (redrawn) (frame update) Display List© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Display Planes Vector 3D Video Display List© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Drawing Modes wmode (Flash), renderMode (AIR) direct GPU gpu CPU cpu Browser Flash Renderer transparent opaque© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • RENDERING OPTIMIZATION© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Rendering Basics The basics: • Keep a shallow display list. Reason: everything in that rectangle is getting redrawn every frame! Display List© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Rendering Basics More basics: • Understand that certain features are just heavy! • Bitmap Effects (shadow, glow, emboss...) • Masks (inherently vector-based) • Alpha channels • Blend modes (add, multiply...) and even... • Embedded fonts (especially Japanese!)© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Rendering Basics More basics: • Keep extraneous stuff off the stage • Use the right framerate • Simplify vector shapes© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Stage Settings • StageQuality.LOW: Lower-quality vector shapes. Never anti-alias, never smooth bitmaps. • StageQuality.MEDIUM: Better vectors. Some anti-aliasing but no bitmaps smoothing. Default value for mobile devices. • StageQuality.HIGH: Always uses anti-aliasing. Uses smoothing on bitmaps depending on whether the SWF is animating. Default value on desktop PCs. • StageQuality.BEST: Best quality. Always anti-alias, always smooth bitmaps.© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Rendering Internals Understand rasterization and the conditions for cached bitmaps to get redrawn! (Designers need to know this too!)© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Bitmap Caching • Lets complex assets be rasterized once instead of every frame. • Turned on automatically if you use bitmap effects Caching is the single most important thing to understand for tuning display list content!© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Bitmap Caching foo.cacheAsBitmap = true; (redrawn) (cached) foo.cacheAsBitmapMatrix = new Matrix(); (cached) (drawn with GPU) (only in AIR!)© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Bitmap Caching Use Monocle to see what’s being cached© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Rendering One more technique: Adjust visual effects at runtime! 500 particles 200 particles© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • RENDERING MODELS© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Rendering Models There are four main rendering models in use today for Flash games. 1. Display List 2. GPU mode 3. Blitting 4. Stage3D© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • 1. Display List Rendering • Plain vanilla flash content, made in Flash Pro • Easiest to build – worst performance. • Suitable for prototypes and light desktop content. Bad for mobile! (because the GPU is not used) • Your key tuning technique will be bitmap caching.© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • 2. GPU Mode • GPU mode is a publish setting available for AIR apps on devices (Android and iOS) • When selected, Flash uses the GPU – vectors and cached surfaces are rendered through hardware. • Can be very powerful with careful, correct use of movieclip.cacheAsBitmapMatrix • Powerful technique today, but not recommended for new/future projects© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • GPU Mode Example Monster Planet SMASH! (GREE) More info:© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • 3. Blitting • Blitting refers to putting a Bitmap object on the stage for your game area and manually drawing contents into it with BitmapData.copyPixels(). • Hence, you manage your own rendering, caching, etc. • Can be very fast in certain restricted cases • Does not scale up for retina/hi-res devices!© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • 4. Stage3D© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • 4. Stage3D • New feature from Flash 11.0, allowing ActionScript to load shader programs directly to the GPU. • Based on AGAL (Adobe Graphics Assembly Language) • AGAL looks like this: m44 op, va0, vc0 dp4 op.x, va0, vc0 dp4 op.y, va0, vc1 • You probably want dp4 op.z, va0, vc2 dp4 op.w, va0, vc3 to use a 2D/3D library! m44 op, va0, vc0 mov v0, va1 (It’s dangerous to go alone!)© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • 4. Stage3D (Take this!) • Two officially supported libraries: • Starling (2D) • Away3D • And many, many more... N2D2 Genome2D© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Stage3D examples© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • NEW / FUTURE TOPICS© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • AS3 Workers create Main Background Worker Worker MessageChannel (regular API (some Flash player) limitations) mutex Shared memory© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • AS3 Workers create Main Background Worker Worker MessageChannel (regular API (some Flash player) limitations) mutex Shared memory© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • ASC2.0 • All new ActionScript compiler! • Included with the Flash Builder 4.7 preview: http://labs.adobe.com/technologies/flashbuilder4-7/ • Key features: • Faster compiles! More optimized bytecode! • Error messages localized to JA, FR, ZH • Inline functions, get/setters (when possible) (use –inline arg) • goto statement (!?!?!?) • Details: http://www.bytearray.org/?p=4789© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Longer term Project Better Better Monocle! Flash Pro! ActionScript!© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • Thanks! andhall@adobe.com @fenomas© 2012 Adobe Systems Incorporated. All Rights Reserved.
  • © 2012 Adobe Systems Incorporated. All Rights Reserved.