<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nicolas Schudel &#187; Performance</title>
	<atom:link href="http://nicolasschudel.name/tag/performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://nicolasschudel.name</link>
	<description>Balancing Design and Development in Online Media</description>
	<lastBuildDate>Sun, 09 May 2010 08:42:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Compressed, High-Performing Animations in Flash</title>
		<link>http://nicolasschudel.name/bitmap-animations/</link>
		<comments>http://nicolasschudel.name/bitmap-animations/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 01:50:22 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://nicolasschudel.name/?p=296</guid>
		<description><![CDATA[<p>Multimedia applications often have interactive elements based on video. The Flash Video data used for such scenes is compressed but processor intensive. I discuss a solution that decompresses the data on the client side, in order to enhance display performance.</p>]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>
Multimedia applications often have interactive elements based on video: For example, a pre-rendered 3D scene that moves according to a user’s interaction. The trick, in such a scene, is to play specific parts of the movie forward and backward to fake movement.
</p>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="480" height="360" id="sculpture"><param name="movie" value="/fileadmin/articles/2009/11/sculpture.swf" /><!--[if !IE]>--><object type="application/x-shockwave-flash" data="/fileadmin/articles/2009/11/sculpture.swf" width="480" height="360"><!--<![endif]--><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><!--[if !IE]>--></object><!--<![endif]--></object>
<p class="wp-caption-text">
This sculpture has been rendered as a movie, with the camera panning 360˚around the object. <br />(Drag with the mouse to turn the object)
</p>

<h2>Embedding Animations</h2>
<p>
There are three basic ways to embed an animated scene into Flash:
</p>
<ul>
<li>In the Flash Video format (FLV);</li>
<li>As a sequence of images, e.g. PNG or JPEG;</li>
<li>As a sequence of vector graphics.</li>
</ul>
<p>
The latter is often forgotten. Tools such as <a href="http://www.cinemax4d.de/flashex/home_us.html">Cinema 4D’s FlashEx renderer</a> can export a scene as a vector animation. If the scene doesn’t contain many objects and has simple texturing, a vector animation would probably be the way to go. The file size stays relatively small, plus the graphics are scalable.
</p>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="480" height="150" id="blimp"><param name="movie" value="/fileadmin/articles/2009/11/blimp.swf" /><!--[if !IE]>--><object type="application/x-shockwave-flash" data="/fileadmin/articles/2009/11/blimp.swf" width="480" height="150"><!--<![endif]--><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><!--[if !IE]>--></object><!--<![endif]--></object>
<p class="wp-caption-text">
A simple 3D object rendered as a vector sequence with FlashEx 2.<br />(Drag with the mouse to turn the object)
</p>
<p>
The other two methods, FLV and image sequences, are both pixel based, but have their own pros and cons. FLV has a decent quality/size ratio. <a href="http://help.adobe.com/en_US/Flash/10.0_UsingFlash/WSBDABD69F-D146-4e5c-9340-BF717A10426C.html">Flash CS4 does not allow F4V files to be embedded directly</a>, so the best codec is the older and less compressing On2 VP6. Interacting with FLV, e.g. jumping between frames quickly or playing it backward, is heavy on the processor. Presumably, the Flash Player has to jump to the nearest proceeding keyframe and process the changes to the current frame each time. On the other end of the spectrum is the image sequence. The compression is on a per-frame basis, so the overall file size will usually turn out much bigger. The display performance, however, is far better than FLV.
</p>
<h2>Eliminating the Cons</h2>
<p>
A combination of the reduced file size of FLV and the performance of an image sequence is possible, if the data gets decompressed on the client side. H.264 encoded video data could be sent through the wire and then be processed into an uncompressed image sequence before being displayed. I wrote a class named BitmapAnimation that parses each frame of a MovieClip (including any FLVs within) and adds it to an array of bitmap data. BitmapAnimation has the same methods as a MovieClip (gotoAndPlay, currentframe etc.), so the two can be interchanged. For instance, I was able to use a BitmapAnimation in place of a MovieClip to create a MovieMaterial in Papervision3d – polymorphism works. 
</p>
<p>
When <a href="/fileadmin/flv_vs_bitmapanimation.zip">compared with simultaneously running FLVs</a>, BitmapAnimations showed a <strong>500% performance increase</strong> on my system. The difference was even bigger with the clips running backward. There may be a performance benefit in converting complicated vector animations to a BitmapAnimation before they are displayed. I have, however, not recently come across a scenario where a pure vector animation alone caused the frame rate to stagnate. 
</p>
<p>
The MovieClip option cacheAsBitmap requires, to my understanding, the frame to be rendered in the Flash display list before it takes effect. This would be the only major difference to BitmapAnimation (where the image is rendered before being displayed). Enabling cacheAsBitmap on MovieClips containing FLV did not show a change in performance in my tests. Because a video is usually viewed once, it makes sense not to cache FLV by default.
</p>
<p>
There is one known drawback when using a BitmapAnimation: Depending on the size of the video and the client’s processor speed, the Flash Player could “freeze” for a few seconds while decompressing the video data. I created an additional class, where I lengthened the processing time by decompressing one frame per half-second. This would allow the video to be prepared in the background without noticeably slowing down the rest of the application. Delayed processing would work best during a loading sequence, where the video is loaded first, then converted to a BitmapAnimation, while the rest of the assets are being retrieved.
</p>
<h2>Usage</h2>
<p>Simply pass a MovieClip to the draw method.</p>
<pre class="brush: as3">
bitmapAnimation = new BitmapAnimation();
bitmapAnimation.draw(movieClip);
addChild(bitmapAnimation);
</pre>
<p>The imported bitmap data can be reused with multiple BitmapAnimations.</p>
<pre class="brush: as3">
var bitmapAnimation1:BitmapAnimation = new BitmapAnimation();
bitmapAnimation1.draw(movieClip);
var bitmapAnimation2:BitmapAnimation = new BitmapAnimation(bitmapAnimation1.bitmapSequence);
</pre>

<h2>Conclusions</h2>
<p>
Pre-rendering a complex MovieClip, such as embedded FLV, using the BitmapAnimation class, may likely show a performance increase. Also, this method may remove the need to embed an image sequence where display performance is an issue. Due to the computation time required for conversion, BitmapAnimations should not be used for long clips. Inputs and feature requests are welcome, just add a comment below.
</p>
<p><a href="/fileadmin/bitmapanimation_classes.zip">Download the classes BitmapAnimation and DelayedBitmapAnimation</a>.</p>
<p><a href="/fileadmin/blimp.zip">Download the blimp example</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://nicolasschudel.name/bitmap-animations/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ActionScript Performance Testing</title>
		<link>http://nicolasschudel.name/actionscript-performance-testing/</link>
		<comments>http://nicolasschudel.name/actionscript-performance-testing/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 20:41:33 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://nicolasschudel.name/?p=277</guid>
		<description><![CDATA[Unlike Javascript, ActionScript usually runs on the same engine (the AVM). This makes specific performance tests worthwhile, in order to compare different code execution speeds. I start a Wiki, where I document such tests and display my results.]]></description>
			<content:encoded><![CDATA[<p>The way I see it, Flash is currently the standard tool for developing and distributing casual games on the net. While the Flash Player has been making leaps in performance these past years, it still has severe limitations in comparison with modern games on other platforms (e.g. game consoles).</p>
<div id="attachment_401" class="wp-caption alignright" style="width: 160px"><a href="http://nicolasschudel.name/fileadmin/articles//2009/11/destruction-derby.png" rel="shadowbox[post-277];player=img;"><img src="http://nicolasschudel.name/fileadmin/articles//2009/11/destruction-derby-150x150.png" alt="Screenshot from the 1995 racing game Destruction Derby" title="Destruction Derby" width="150" height="150" class="size-thumbnail wp-image-401" /></a><p class="wp-caption-text">Screenshot from the 1995 racing game Destruction Derby</p></div>
<p>It seems that the graphics performance is comparable to games that came out in 1995 on the PC, before graphics hardware became widespread. Imagine running a game like <a href="http://en.wikipedia.org/wiki/Dark_Forces">Dark Forces</a> or <a href="http://en.wikipedia.org/wiki/Destruction_Derby_(video_game)">Destruction Derby</a> inside the browser. In a nutshell, on today’s average computer, the Flash graphics performance is <a href="http://en.wikipedia.org/wiki/Quake">Quake 1</a> tops. Broad statements aside, it is important to know what code flies on the Flash Player when developing games and interactive applications.</p>
<p>I’d like to know what basic code will perform best in a given situation. Therefore, I have started to extract these parts of code from my projects and test them against alternative methods, attempting to quantify the execution speed on the <abbr title="ActionScript Virtual Machine">AVM</abbr>. Unlike Javascript, ActionScript usually runs on the same engine; This makes such specific tests worthwhile.</p>
<p>I have gathered performance tests from a couple of my projects and put them into the <a href="http://nicolasschudel.name/actionscript-performance-wiki/Main_Page"><strong>ActionScript Performance Wiki</strong></a>. It is open to anonymous editors, so anybody is free to add their own tests.</p>
]]></content:encoded>
			<wfw:commentRss>http://nicolasschudel.name/actionscript-performance-testing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
