Issuu on Google+

Flash Performance - Flashmagazine

Flash Performance By Scott Bilas, Oberon Media, Inc. In this paper so far we've covered many disadvantages of the Flash platform, nearly all of which are fairly minor and can be worked around. Flash is like any platform, with its own list of weird quirks and annoying features and bugs. However, there is one major problem that deserves its own section: performance. ActionScript can be very slow. Bytecode execution is ok, probably on par with other scripting languages, but there is a significant problem with entry points. Setting up the execution context to call into the virtual machine and tearing it down again after a function exits is extremely expensive. Less expensive, but still significant, is a script-to-script function call. Optimizing ActionScript is straightforward: - Minimize entry points into the code. For example, use a traditional game main loop rather than a lot of onEnterFrames attached to MovieClip-derived classes for every game object on the screen. - Profile, profile, profile. Nothing shows what's slow like ASProf (see Flash Resources at the end of this paper). - Manually inline functions when necessary. When in inner loops, use local variables, which are specifically optimized in "registers", instead of global variables. - Publish for Flash 7, which is much faster than Flash 6 (mostly due to the "registers"). - Scan the blogs and mailing list archives for tips on optimizing ActionScript performance. There are many tricks out there, too many to cover here, but this site gathers a lot of analysis and links in one place: Note that many of these may be out of date due to Flash 7 and need re-testing. Worse than scripting performance is graphics performance. Flash is basically a 2D rasterizer in software with zero caching other than on the primary surface. Each bitmap being rendered is actually a textured fill of a four-sided shape, rendered through a generic rasterizer. It's very pretty, but can be very slow. Little work is apparently done inside the Player to optimize for bitmaps on integral coordinates with an identity texture transform. There is a dirty rectangle system that works fairly well, but it is spoiled by a final step in the renderer that unions all the dirty rectangles together for the final update area. This means that on a screen with a lot of detail, a flashing icon in one corner of the screen, with the gameplay action in the other corner, causes the entire screen to be redrawn each time the icon changes. There is also overhead in maintaining each graphical object on the screen, and managing it as part of the display list. Optimizing graphics is also straightforward, although it may not be very appealing: - Avoid making action games where the whole screen is scrolling. Feeding Frenzy is a great example of something not to attempt in Flash. - Minimize the number of objects onscreen at once. - Avoid UI designs that have animated indicators at the edge of the screen. These will expand the final union size for dirty rectangle rendering, increasing the update cost. - Avoid large full-screen effects unless the screen is very simple (such as on a rewards screen). If possible, downshift the quality temporarily while a large full-screen effect is playing. - Target frame rates for 16 or 20 fps. A consistent frame rate feels much better than a high frame rate, and it reduces the per-frame overhead that Flash incurs from maintaining its objects. - Use lower resolutions - the graphics problem only really kicks in at higher resolutions. For web resolutions, we can file:///C|/Documents%20and%20Settings/mdoherty/My%20Documents/performance/1079.htm (1 of 4) [03/11/2007 13:35:48]

Flash Performance - Flashmagazine

get away with pretty much anything. At 800x600 though, the pixel throughput of Flash really starts to hurt. - If an animated object needs to be hidden, remove it from the screen instead of setting its _visible member to false. An invisible animating object still (inexplicably) dirties the screen. There's really no way around it. Flash is not designed for fast paced full-screen animated graphics of any complexity, but with careful optimization and some modifications to the game design we can still make it work for us. Odds and Ends >>> Published: 26 Mar 2005

● ● ● ● ● ● ● ●

About Flashmagazine Application listing Articles Book Reviews News Resource Links Software reviews Tutorials ❍ ❍ ❍ ❍

Video.maru Rollover effect using masks sendAndLoad, PHP and LiveDocs What About Flash? ■ ■ ■ ■ ■ ■ ■ ■ ■ ■

❍ ❍ ❍ ❍

Casual Games The Development Platform What is Flash? Advantages of Flash What is a Flash Game? Developing with Flash Flash Performance Odds and Ends Conclusion Flash Resources

AS2Unit - Part 1 RIA welcome Getting Across to Flash with Java More...

FLASH SHOP CS3 Bundles Need more than two of the new CS3 tools? Consider getting a bundle suited to your production flow. From the basic to the complete - now it is easier to find a suite that suits you.

file:///C|/Documents%20and%20Settings/mdoherty/My%20Documents/performance/1079.htm (2 of 4) [03/11/2007 13:35:48]

Flash Performance - Flashmagazine

Click here to order

JOIN THE LIST Stay current on what's happening in Flash business. Sign up now for news, reviews, competitions and more.

Submit Query

Featured Articles FlashForum 2007 Germany FlashForum is the largest Flash Community site in Germany, with more than 83.000 members. Given such numbers, there's no problem filling a full 2-track conference with local talent. Flash 9 CS3 (P)review, Screenshots of the new IDE and the new features explained.

Projector Tool Showdown 6 of the hottest tools for creating software with Flash are reviewed in this comparative review. Find the tool that best suits your need and skillset.

Upcoming conferences

Link Partners Internet Marketing Reliable and Affordable Web Hosting Free Flash Tutorials

file:///C|/Documents%20and%20Settings/mdoherty/My%20Documents/performance/1079.htm (3 of 4) [03/11/2007 13:35:48]

Flash Performance - Flashmagazine

Home | Top of page | Site map Some rights reserved.Click for details.

file:///C|/Documents%20and%20Settings/mdoherty/My%20Documents/performance/1079.htm (4 of 4) [03/11/2007 13:35:48]