<?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>Ryan Phelan &#187; Optimization</title>
	<atom:link href="http://www.rphelan.com/tag/optimization/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rphelan.com</link>
	<description>Exploring Flex, Design, and Visualization</description>
	<lastBuildDate>Thu, 12 Aug 2010 14:56:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>FLVPlayback Memory Leak &#8211; Fixed</title>
		<link>http://www.rphelan.com/2008/09/22/flvplayback-memory-leak-fixed/</link>
		<comments>http://www.rphelan.com/2008/09/22/flvplayback-memory-leak-fixed/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 19:46:42 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Custom Components]]></category>
		<category><![CDATA[FLVPlayback]]></category>
		<category><![CDATA[Memory Management]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Profiling]]></category>

		<guid isPermaLink="false">http://www.rphelan.com/?p=107</guid>
		<description><![CDATA[So the Flash CS3 FLVPlayback control has a memory leak.  Based on prior experiences with Flash components, I'm not too shocked.... here's my solution. I'm working on a straight AS3 project that has a dynamically generated pop-up type window which can contain a video player. You open the window, a video player is created - [...]]]></description>
			<content:encoded><![CDATA[<p>So the Flash CS3 FLVPlayback control has a memory leak.  Based on prior experiences with Flash components, I'm not too shocked.... here's my solution.</p>
<p>I'm working on a straight AS3 project that has a dynamically generated pop-up type window which can contain a video player. You open the window, a video player is created - you close it, and the player is removed.  The client requested that we use Flash's FLVPlayback component.   When I started doing some profiling I noticed that instances of FLVPlayback and its subcomponents weren't getting garbage collected.  After several hours of frustration, I created a project from scratch that just loaded and unloaded FLVPlaybacks to see if I could recreate the problem.  Here it is:</p>
<p><a href="http://www.rphelan.com/flex/FLVMemoryLeak/FLVMemoryLeak.html">Application</a> -  <a href="http://www.rphelan.com/flex/FLVMemoryLeak/srcview/index.html">Source</a></p>
<p>You'll notice that each time you create a video player, System.totalMemory goes up by several megs!  (your results may vary)  and it never comes back down.  Here's what it looks like after creating and destroying 10 FLVPlaybacks:</p>
<p><a href="http://www.rphelan.com/flex/uploads/2008/09/flv-leak.jpg"><img class="alignnone size-full wp-image-109" title="flv-leak" src="http://www.rphelan.com/flex/uploads/2008/09/flv-leak.jpg" alt="" width="500" height="477" /></a></p>
<p><em>Note that I sorted by current number of instances, and removed flash.*.* from the filters list so that I could see the Timers.</em></p>
<p>All of the objects in the fl.video.skin package are still hanging around.  I actually have no idea why it created two skins for each instance, but I'm sure there is a good explanation... the main point is that none of these objects were getting garbage collected.</p>
<p>It took a lot of rooting around in the source before figuring out what the culprits were, but I knew I would have to do some manual cleanup work in order to clear out all object references.  My solution was to subclass FLVPlayback and implement a dispose() method to do the necessary cleanup.  (Just for fun, I got the same solution working with an old school prototype hack, but I think we're supposed to pretend those don't exist anymore.)  Now, I may have been a little aggressive on my cleanup - but the overhead is tiny, and it's important to me that this always works.  If anybody knows of a simpler solution, please post it in the comments.  Here's the breakdown:</p>
<ol>
<li>Call stop().  Obviously if the video is still playing it cannot be garbage collected.</li>
<li>Stop all timers in FLVPlayback and UIManager and remove the TimerEvent.TIMER event listeners attached to each one.</li>
<li>Call the close() method on the VideoPlayer instances.  This will stop their timers, remove event listeners, and close NetConnections.</li>
</ol>
<p>Here's the same application, but using FLVPlayback2 and the FLVPlayback2.dispose() method:</p>
<p><a href="http://www.rphelan.com/flex/FLVMemoryLeak/FLVMemoryLeakFixed.html">Application</a> -  <a href="http://www.rphelan.com/flex/FLVMemoryLeak/srcview/index.html">Source</a></p>
<p>And here are the profiler results:</p>
<p><a href="http://www.rphelan.com/flex/uploads/2008/09/flv-fixed.jpg"><img class="alignnone size-full wp-image-112" title="flv-fixed" src="http://www.rphelan.com/flex/uploads/2008/09/flv-fixed.jpg" alt="" width="500" height="478" /></a></p>
<p>Success!  I wish that hadn't taken so much detective work... why aren't the Flash components built to the same standards as the Flex ones?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rphelan.com/2008/09/22/flvplayback-memory-leak-fixed/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Some Useful Eclipse Plugins for Flex Developers</title>
		<link>http://www.rphelan.com/2008/05/01/some-useful-eclipse-plugins-for-flex-developers/</link>
		<comments>http://www.rphelan.com/2008/05/01/some-useful-eclipse-plugins-for-flex-developers/#comments</comments>
		<pubDate>Thu, 01 May 2008 23:00:02 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[Workflow]]></category>
		<category><![CDATA[JIRA]]></category>
		<category><![CDATA[Memory Management]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[RegEx]]></category>

		<guid isPermaLink="false">http://www.rphelan.com/?p=29</guid>
		<description><![CDATA[These are some of the plugins I've been experimenting with lately to improve workflow, performance, etc. AnyEdit Tools Adds a bunch of useful tools into the right-click context menu, in a submenu called "Convert". My personal favorites are the "Convert -> Leading tabs to spaces" and "Convert -> Leading spaces to tabs". I know that [...]]]></description>
			<content:encoded><![CDATA[<p>These are some of the plugins I've been experimenting with lately to improve workflow, performance, etc.</p>
<h4><a href="http://andrei.gmxhome.de/anyedit/index.html">AnyEdit Tools</a></h4>
<p>Adds a bunch of useful tools into the right-click context menu, in a submenu called "Convert". My personal favorites are the "Convert <code>-></code> Leading tabs to spaces" and "Convert <code>-></code> Leading spaces to tabs".  I know that the <a href="http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions">Flex Coding Conventions</a> tell you not to use tabs, but I prefer tabs to spaces in my own code because it keeps everything nicely formatted and easy to maintain.  If I need to say, paste some code into a blog entry, I use the AnyEdit tools to convert those tabs back to spaces so that it displays correctly.  I also frequently copy and paste bits of code found on websites, the user documentation, etc. into my source, and want to convert those tabs back to spaces.  Huge time saver!</p>
<ul>
<li>Convert <code>-></code> Camel <code><-></code> Underscores</li>
<li>Convert <code>-></code> Leading tabs to spaces</li>
<li>Convert <code>-></code> Leading spaces to tabs</li>
<li>Convert <code>-></code> Chars to html entities</li>
<li>Convert <code>-></code> Html entities to chars</li>
<li>Convert <code>-></code> To / From Unicode notation</li>
<li>Convert <code>-></code> To / From Base64</li>
</ul>
<h4><a href="http://regex-util.sourceforge.net/description.html">RegEx Editor</a></h4>
<p>This is a "View" that you can add to your perspective via Window <code>-></code> Show View <code>-></code> Other <code>-></code> Regex Util.  You can enter a regular expression and a string to test against.  It supports syntax highlighting and has very useful tooltips for characters that are part of regular expression syntax.</p>
<h4><a href="http://www.eclipse.org/mylyn/">Mylyn</a></h4>
<p>I'm experimenting with using this at work to connect to our <a href="http://www.atlassian.com/software/jira/">JIRA </a>repository.  (You could use it to connect to <a href="https://bugs.adobe.com/">Adobe's bug tracking system</a> too).  Also works for Bugzilla, Trac, and possibly others.  Its cool that it pops up a message right in Eclipse whenever a new task is assigned to you, and also that you can tightly integrate it into your regular workflow.  The downside is that it seems to be lacking some of the basic features that the web interface has which (because of our system's configuration) prevents me from being able to create new tasks.  Maybe I just need to wait another version or two?</p>
<h4><a href="http://www.rphelan.com/2008/03/27/tweaking-compiler-performance-in-flex-builder/">Heap Status</a></h4>
<p>I <a href="http://www.rphelan.com/2008/03/27/tweaking-compiler-performance-in-flex-builder/">wrote a separate blog post</a> about this a while back, its cool to be able to get a glimpse of how the VM is managing your memory.</p>
<h4><a href="http://suif.stanford.edu/pub/keepresident/">Keep Resident</a></h4>
<p>Uses some Windows hooks to try and keep Eclipse in memory as much as possible.  Use this if you are experiencing frequent "hang-ups" with your IDE.</p>
<blockquote><p>The performance of Eclipse (and other large Java applications) has long suffered due to the Windows virtual memory manager. Windows has a tendency to preemptively swap Java processes out of physical memory, even when there is still plenty of physical memory available. This interacts very poorly with Java processes, which do not have good locality and touch a lot of memory. The problem is exacerbated when Java performs garbage collection, which causes the Java process to touch lots of memory that has been paged out to disk. Ever had Eclipse randomly hang for 15-20 seconds? This is most likely the culprit.</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.rphelan.com/2008/05/01/some-useful-eclipse-plugins-for-flex-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tweaking Compiler Performance in Flex Builder</title>
		<link>http://www.rphelan.com/2008/03/27/tweaking-compiler-performance-in-flex-builder/</link>
		<comments>http://www.rphelan.com/2008/03/27/tweaking-compiler-performance-in-flex-builder/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 20:22:39 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex Builder]]></category>
		<category><![CDATA[Workflow]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Flex Compiler]]></category>
		<category><![CDATA[Memory Management]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://www.rphelan.com/2008/03/27/tweaking-compiler-performance-in-flex-builder/</guid>
		<description><![CDATA[Using some Eclipse and Java tricks to better manage Flex Builder's memory, and (hopefully) increase compiler performance.]]></description>
			<content:encoded><![CDATA[<p><em>Using some Eclipse and Java tricks to better manage Flex Builder's memory, and (hopefully) increase compiler performance.</em></p>
<p>My coworker <a href="http://www.axelscript.com" target="_blank">Axel</a> discovered a nice Eclipse trick the other day.  If you go to Window-&gt;Preferences-&gt;General, there is an option called "Show heap status" (if you don't see it, check out my note at the end of this post).  This option is disabled by default.  When it is selected, you will notice a bar in the lower right hand corner of the screen indicating Eclipse's current memory usage.  If you right-click this bar, there is another option to show the max heap size.  Good stuff.  The best part is the little trash can button which you can use to force garbage collection to be run.  After running Eclipse for a while, this often has a big effect on the memory usage, and runs surprisingly fast on my machine (less than one second).</p>
<p><strong>Overriding the default memory allocation:</strong><br />
After watching the heap's behavior for a day or two I noticed that the start size of the heap (a paltry 64MB) seems to be insufficient for compiling any of my Flex projects.  When you do a compile, you will see Java incrementally increase the size of the heap to accommodate.  Since there is some overhead in memory allocation, we can optimize this a bit by telling Java how much memory to allocate to the virtual machine when it starts up.  You do this by setting the <code>-vmargs</code> flag at the command line.</p>
<p>Try running Eclipse using <code>-vmargs -Xms256M -Xmx512M</code> to set the start heap size at 256mb and max at 512mb (I think the default max is around 256). Take care not to set either of these too high, or it will bog down the rest of your machine... and make sure you have enough memory installed to begin with.  I've got 2GB of RAM and I'm not running any other heavy applications alongside Eclipse, so allocating a few hundred extra megs shouldn't be an issue for me.</p>
<p>In Windows, you can set these values using a shortcut.  Right click your shortcut to Eclipse and select "Properties".  Add the flags after the existing Target (and outside of the quotes).  It should look something like this:</p>
<p><code>"C:\Program Files\eclipse\eclipse.exe" -vmargs -Xms256M -Xmx512M</code></p>
<p><strong>Memory usage at startup... </strong></p>
<p><em>Before:</em> <img src="http://www.rphelan.com/flex/uploads/2008/03/heap_before.PNG" alt="heap_before.PNG" /></p>
<p><em>After:</em> <img src="http://www.rphelan.com/flex/uploads/2008/03/heap_after.PNG" alt="heap_after.PNG" /></p>
<p>I don't have any <em>definitive proof</em> that this makes any difference on compiler performance,  and results will always vary from one machine to the next, but its a pretty easy trick and has worked great for me so far.</p>
<p><strong>Note:</strong><br />
If you do not see the "Show heap status" option in your preferences (and I don't think you will if you have the standalone version of Flex Builder), you will just have to obtain the plugin manually.</p>
<p>From the <a href="http://dev.eclipse.org/viewcvs/index.cgi/platform-ui-home/dev.html?revision=1.38" target="_blank">Eclipse site</a>:</p>
<blockquote><p>The Heap Status plug-in shows the current Java heap usage in the status line (total heap and amount used). A button allows you to force a garbage collect. It includes a preference page (Window &gt; Preferences &gt; Workbench &gt; Memory Indicator) which lets you turn it on and off. This plug-in works on Eclipse 2.1, 3.0, 3.0.1 and 3.1.</p>
<p>The Heap Status plug-in can be obtained via the Platform UI team's update site.<br />
Use Help &gt; Software Updates &gt; Find and Install &gt; Search for new features to install &gt; New Remote Site, and give the following as the URL.<br />
<a href="http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-ui-home/updates" target="_blank">http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-ui-home/updates</a></p>
<p>When prompted, choose Yes to restart.</p>
<p>If you don't see the status indicator in the status line, or if the preference page is missing, restart eclipse with the -clean command line option.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.rphelan.com/2008/03/27/tweaking-compiler-performance-in-flex-builder/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
