{"id":109,"date":"2009-01-28T17:02:27","date_gmt":"2009-01-28T22:02:27","guid":{"rendered":"http:\/\/www.stephencalenderblog.com\/?p=109"},"modified":"2025-12-01T20:25:22","modified_gmt":"2025-12-02T01:25:22","slug":"top-ten-actionscript-performance-tips","status":"publish","type":"post","link":"https:\/\/www.stephencalenderblog.com\/?p=109","title":{"rendered":"Top Ten ActionScript Performance Tips"},"content":{"rendered":"\n<p>These are tips I have personally used and have indisputable results. Of all the things you can do to improve performance these are the most effective and efficient changes that you can make.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>10. Make sure your performance problem is not a memory problem<\/p>\n\n\n\n<p>Debugging 101 is to correctly identify the source of your problem. If you are using up all of your available RAM with references to artwork or other memory intensive structures your processor will be crippled by having to retrieve and set data from slower memory. If your application slows over time it is most likely a memory leak issue were objects you intended to delete are still being stored. The other reason to check for this issue first is that it is very easy to see how much memory that you are using, Flash does everything for you, just call System.totalMemory. Easier still, just bring up the task manager and consult your page file usage.<\/p>\n\n\n\n<p>9. Unnecessary import statements<\/p>\n\n\n\n<p>Not the biggest time saver unless you are generating many instances of the class or the class has a large number of function calls made to it. However, it is a very easy way to improve performance. If you are programming using Python, <a href=\"https:\/\/docs.pipenv.org\/\">pipenv<\/a> may help simply or declutter your workflow and make it easier to identify security vulnerabilities.<\/p>\n\n\n\n<p>8. Sprites and MovieClips<\/p>\n\n\n\n<p>You only need to use the MovieClip type if the object has multiple frames, you can export for ActionScript Library objects extending the Sprite class instead of the MovieClip class.<\/p>\n\n\n\n<p>7. Resolve issues of promotion, unknown, or incorrect object types<\/p>\n\n\n\n<p>ActionScript can waste a lot of time determining the type of an object if it does not understand the object type, or if ActionScript has to cast an object type. Pay close attention the object types of function parameters and types functions return as these are typical problem sources. Individually, object type compatibility changes are not going to save you that much time. In most cases this is something that you would need to be doing thousands of times to see a sizable difference in performance.<\/p>\n\n\n\n<p>6. Unnecessary operations and function calls<\/p>\n\n\n\n<p>Instead of dividing, multiply. Instead of calling Flash\u2019s math class for simple things like floor and round, calculate them yourself. Rank your if statements in order of comparisons most likely to be true. In for and while statements locally store function values instead of repeated accessing them and reuse objects if possible. Similar to promotion issues, individual calls are not worth worrying about, but there can be a big difference in loops iterated several hundred times.<\/p>\n\n\n\n<p>5. Avoid using masks<\/p>\n\n\n\n<p>If you need to mask a square area use the display object&#8217;s &#8216;scrollRect&#8217; property instead. If you need a shape that is not a square, place that shape over the object with the scrollRect property.<\/p>\n\n\n\n<p>4. Disable events that you do not need<\/p>\n\n\n\n<p>Dispatching events is one of the more expensive function calls that you can make. Every class that extends InteractiveObject (which encompasses every display object) generates a host of events that you most likely do not need. Take the time to set MouseEnabled and MouseChildren to false to keep your event system as clean as possible. Also, make sure to remove event listeners and onEnterFrame events when you no longer need them.<\/p>\n\n\n\n<p>3. Limit your art assets attached to the stage<\/p>\n\n\n\n<p>No sense in traversing render nodes if they are not actively being used. If it is an object that is not frequently visible I will completely destroy it and recreate it when it is needed again. The archetype to employ this strategy is menu systems.<\/p>\n\n\n\n<p>2. Cache appropriate objects<\/p>\n\n\n\n<p>Cache your most expensive objects to render (set cacheAsBitmap property to true). Caching an object stores it in memory, and if it is static, you will only have to pay to render it once. Filter effects cause objects to be cached, if many of your objects have filters applied to them they could be the cause of a memory problem. If a cached object is animated, scaling, or rotating it will be re-cached for every one of those graphic manipulations which is a heavy burden for the processor.<\/p>\n\n\n\n<p>1. Use the right type of art asset for the job<\/p>\n\n\n\n<p>Use vector art for your simplest objects and png or jpg file types for the more complex graphics. Rendering and graphic related function calls are the most processor intensive routines; therefore, rendering is usually where you can make the most improvement. Check out an objects memory consumption by going to File -&gt; publish settings -&gt; flash tab -&gt; generate size report to get a rough idea of which assets to change.<\/p>\n\n\n\n<p>If you are curious about other optimization techniques, want an idea of the expense of related operations, or to get a general idea of where your processor time is being spent I would suggest reading my <a href=\"https:\/\/www.stephencalenderblog.com\/?p=7\">benchmarking series<\/a>.<\/p>\n\n\n\n<p>Thanks for reading, and remember, we are all in this together.<\/p>\n\n\n\n<p>Edit (April 4th, 2013): <a href=\"http:\/\/www.adobe.com\/devnet\/flash\/articles\/efficiency-tips.html\">Long overdue (late 2011), Adobe released a comprehensive list of performance tips<\/a> and general development recommendations. <a href=\"http:\/\/udn.epicgames.com\/Three\/ScaleformActionScriptBestPractices.html\">Epic games also has a great article of best practices with performance in mind<\/a>, which is still relevant to even if you are not using Scaleform or the Unreal game engine.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>&nbsp;<\/td><td><a href=\"http:\/\/reddit.com\/submit\"> <img decoding=\"async\" src=\"http:\/\/reddit.com\/static\/spreddit7.gif\" alt=\"submit to reddit\" border=\"0\"> <\/a><\/td><td>\n<table>\n<tbody>\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/static.delicious.com\/img\/delicious.small.gif\" alt=\"Delicious\" width=\"10\" height=\"10\"><\/td>\n<td><a href=\"http:\/\/delicious.com\/save\"> Bookmark this on Delicious<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td><td><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/static.delicious.com\/img\/delicious.small.gif\" alt=\"Delicious\" width=\"10\" height=\"10\"><\/td><td><a href=\"http:\/\/delicious.com\/save\"> Bookmark this on Delicious<\/a><\/td><td><script src=\"http:\/\/www.stumbleupon.com\/hostedbadge.php?s=2\"><\/script><\/td><\/tr><tr><td><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/static.delicious.com\/img\/delicious.small.gif\" alt=\"Delicious\" width=\"10\" height=\"10\"><\/td><td><a href=\"http:\/\/delicious.com\/save\"> Bookmark this on Delicious<\/a><\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>These are tips I have personally used and have indisputable results. Of all the things you can do to improve performance these are the most effective and efficient changes that you can make.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-actionscript-30"],"_links":{"self":[{"href":"https:\/\/www.stephencalenderblog.com\/index.php?rest_route=\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.stephencalenderblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stephencalenderblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stephencalenderblog.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stephencalenderblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=109"}],"version-history":[{"count":11,"href":"https:\/\/www.stephencalenderblog.com\/index.php?rest_route=\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":912,"href":"https:\/\/www.stephencalenderblog.com\/index.php?rest_route=\/wp\/v2\/posts\/109\/revisions\/912"}],"wp:attachment":[{"href":"https:\/\/www.stephencalenderblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stephencalenderblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stephencalenderblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}