<?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>Vladimir Vukićević &#187; Firefox</title>
	<atom:link href="http://blog.vlad1.com/category/firefox/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.vlad1.com</link>
	<description>Words</description>
	<lastBuildDate>Thu, 06 Oct 2011 02:40:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>WebGL in Firefox 4 Beta 8</title>
		<link>http://blog.vlad1.com/2010/12/21/webgl-in-firefox-4-beta-8/</link>
		<comments>http://blog.vlad1.com/2010/12/21/webgl-in-firefox-4-beta-8/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 19:00:08 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Canvas 3D]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[webgl]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=355</guid>
		<description><![CDATA[One of the parts of Firefox 4 that I&#8217;m excited about is support for WebGL, a standard for accelerated 3D rendering on the web. We&#8217;ve been working on this for quite a while, and I&#8217;ve been doing experiments with a similar kind of 3D support for a few years now. With the upcoming release of [...]]]></description>
			<content:encoded><![CDATA[<p>One of the parts of Firefox 4 that I&#8217;m excited about is support for WebGL, a standard for accelerated 3D rendering on the web.  We&#8217;ve been working on this for quite a while, and I&#8217;ve been doing experiments with a similar kind of 3D support for a few years now.  With the upcoming release of Firefox 4 Beta 8, WebGL support is starting to firm up.</p>
<h2>What is WebGL?</h2>
<p><a href="http://webgl.org/">WebGL</a> allows web developers to take advantage of the 3D capabilities of modern video cards to add 3D displays to their web applications. Apps that would have been possible only on the desktop or with plugins become possible in any modern browser that supports WebGL: 3D games, interactive product displays, scientific and medical visualization, shared virtual environments, and 3D content creation all become possible on the web.</p>
<p>For users, this means a more interactive and visually interesting web. It means having access to a wider range of applications and experiences on any device that supports the full web, instead of being limited to specific devices or platforms.</p>
<p>WebGL is being developed within the Khronos Group, the same group responsible for OpenGL and OpenGL ES.  Members of the WebGL group include Mozilla, Google, Opera, and Apple, as well as a number of hardware vendors who are interested in making sure that WebGL content can run well on both desktop and mobile hardware.  There&#8217;s a lot of support for WebGL!</p>
<p>I recently gave a talk at NVidia&#8217;s GPU Technology Conference about WebGL.  The <a href="http://nvidia.fullviewmedia.com/gtc2010/0921-a8-2113.html">video stream is available</a> (though sadly not using HTML5 video!), and it&#8217;s a good (though technical) overview of WebGL.</p>
<h2>Let me check out some demos!</h2>
<p>Here&#8217;s a couple of demos showcasing WebGL technology by Mozilla, Google, and others.</p>
<p>Some platform-specific notes: WebGL is currently disabled on Linux due to some build issues; it should be getting re-enabled in beta 9.  For Windows users, you may need to install the <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=2da43d38-db71-4c1b-bc6a-9b6652cd92a3&amp;displaylang=en">DirectX Runtime</a> in case these demos don&#8217;t work for you or if they have glitches &#8212; this allows Firefox to use an alternate rendering path that might be better supported on your system, especially on systems with Intel GPUs.  We&#8217;re working on removing the need for this separate install in a future build.</p>
<table class="aligncenter" border="0">
<tbody>
<tr>
<td>
<p><div id="attachment_359" class="wp-caption alignnone" style="width: 210px"><a href="http://videos.mozilla.org/serv/mozhacks/flight-of-the-navigator/" target="_blank"><img class="size-full wp-image-359 " title="Flight of the Navigator" src="http://blog.vlad1.com/wp-content/uploads/2010/12/fotn.png" alt="Flight of the Navigator" width="200" height="200" /></a><p class="wp-caption-text">Flight of the Navigator</p></div></td>
<td>
<p><div id="attachment_360" class="wp-caption alignnone" style="width: 210px"><a href="http://bodybrowser.googlelabs.com/" target="_blank"><img class="size-full wp-image-360" title="Body Browser" src="http://blog.vlad1.com/wp-content/uploads/2010/12/bodybrowser.png" alt="Body Browser" width="200" height="200" /></a><p class="wp-caption-text">Body Browser by Google</p></div></td>
<td>
<p><div id="attachment_358" class="wp-caption alignnone" style="width: 210px"><a href="http://webglsamples.googlecode.com/hg/aquarium/aquarium.html" target="_blank"><img class="size-full wp-image-358 " title="WebGL Aquarium" src="http://blog.vlad1.com/wp-content/uploads/2010/12/aquarium.png" alt="WebGL Aquarium" width="200" height="200" /></a><p class="wp-caption-text">WebGL Aquarium</p></div></td>
</tr>
</tbody>
</table>
<p>Check out Dave&#8217;s post for more <a href="http://vocamus.net/dave/?p=1233">details about the Flight of the Navigator</a> demo.  You can find many more projects and demos using WebGL on the web and linked from <a href="http://webgl.org">webgl.org</a> &#8212; for example, some other great examples are a <a href="http://www.3dtin.com/" target="_blank">web-based 3D editor called 3DTin</a> and <a href="http://www.ibiblio.org/e-notes/webgl/waves/annihilation.html" target="_blank">a vortex/anti-vortex annihilation simulation</a>,</p>
<h2>Give me more technical details!</h2>
<p>WebGL brings the OpenGL ES 2.0 API to the HTML5 Canvas element.  3D content is confined to the canvas, but the canvas follows normal HTML compositing rules.  For example, a 2D UI can be layered on top of the 3D scene using normal CSS mechanisms, and content underneath the canvas will show through transparent portions.  In addition, CSS properties can be applied to the canvas itself, for effects like fading the entire scene in or out.</p>
<p>The WebGL API interacts well with the rest of the web platform; specifically, support is provided for loading 3D textures from HTML images or videos, and keyboard and mouse input is handled using familiar DOM events.</p>
<h2>As a developer, how do I learn more about WebGL?</h2>
<p>WebGL is based on <a href="http://www.khronos.org/opengles/2_X/">OpenGL ES 2.0</a>, which just so happens to be the same 3D API used for Android and iOS development, as well as being based on the desktop OpenGL API.  Many resources available for ES 2.0 development translate almost directly to WebGL development.</p>
<p>Unlike desktop or mobile OpenGL development, it&#8217;s very easy to get started with WebGL.  Some simple HTML and JS content lets you immediately start writing WebGL code.  A number of tutorials already exist that focus on WebGL; you can take a look at <a href="http://learningwebgl.com/blog/?p=28">Learning WebGL&#8217;s lessons</a> to help you get started.</p>
<p>Here are some web resources with more information:</p>
<ul>
<li><a href="http://webgl.org/">webgl.org</a> &#8212; official WebGL page, including specification and resource links</li>
<li><a href="http://learningwebgl.com/">learningwebgl.com</a> &#8212; blog with regular updates on WebGL happenings</li>
</ul>
<h2>Future Work</h2>
<p>WebGL focuses on OpenGL ES 2.0 feature compatibility to ensure content compatibility with mobile devices.  However, ES 2.0 is behind the latest advances on the desktop today.  In the future, various desktop features may become available in WebGL in the form of extensions.</p>
<p>There&#8217;s still some work to do on the Firefox side as well, in particular removing some performance bottlenecks on Windows when we&#8217;re using ANGLE for Direct3D compatibility.</p>
<h2>Wrap up</h2>
<p>WebGL will enable web developers to create new experiences for their users.  As with any new technology, initial experimentation will lead to developers understanding better how to fully leverage WebGL. There&#8217;s already tremendous interest in WebGL, as can be seen by the wealth of frameworks and samples, even before WebGL has been released as part of any final shipping browser version!  By including WebGL in Firefox, and along with our work on HTML5 video and audio support (including direct audio data access), Firefox supports a full set of web<br />
technologies for building rich and compelling applications on the web.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2010/12/21/webgl-in-firefox-4-beta-8/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Building Fennec for Android under Win32</title>
		<link>http://blog.vlad1.com/2010/11/01/building-fennec-for-android-under-win32/</link>
		<comments>http://blog.vlad1.com/2010/11/01/building-fennec-for-android-under-win32/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 21:50:33 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[fennec]]></category>
		<category><![CDATA[win32]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=348</guid>
		<description><![CDATA[I&#8217;ve been using Windows 7 as my primary development platform for a while (don&#8217;t let the MacBook Pro fool you &#8212; it&#8217;s probably spent less than an hour total in MacOS X), but have always needed to use a virtual machine running Linux to make Android builds.  I don&#8217;t mind working in a VM, but [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Windows 7 as my primary development platform for a while (don&#8217;t let the MacBook Pro fool you &#8212; it&#8217;s probably spent less than an hour total in MacOS X), but have always needed to use a virtual machine running Linux to make Android builds.  I don&#8217;t mind working in a VM, but it takes up a large chunk of memory, and makes it hard to share code/patches with my main source trees.</p>
<p>However, Google provides the cross-compilers for Windows as well; since the external drive that had my VM on it died a week ago, it seemed like a good opportunity to get the build working under Windows.  Because the native compilers are built using cygwin, this is a bit convoluted, but seems to work.  You&#8217;ll need some msys and cygwin tools, as well as the standard Android build prereqs (Java, SDK, NDK):</p>
<ul>
<li>mozilla-build installed</li>
<li>the <a href="http://ftp.mozilla.org/pub/mozilla.org/mozilla/source/wintools.zip">mingw moztools</a>, unpacked somewhere like c:\mozilla-build\moztools-mingw (see bug comment as to why this is required)</li>
<li>cygwin installed, including gcc/g++ and the mingw 4.5.1 compilers</li>
<li>a <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">JDK</a> (note: I don&#8217;t know if OpenJDK supports Windows; if it does, that&#8217;s also an option)</li>
<li>the <a href="http://developer.android.com/sdk/index.html">Android SDK</a> (with at least the platform level 8 SDK)</li>
<li>the <a href="http://www.crystax.net/android/ndk-r4.php">Crystax r4 NDK</a> for Win32</li>
<li>the patches from <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=607975">bug 607975</a></li>
</ul>
<p>You do the build inside the standard mozilla-build shell prompt (<em>not</em> a cygwin shell).  However, you&#8217;ll need to copy *.dll from c:/cygwin/bin (assuming you installed cygwin in c:/cygwin) into a new directory, such as c:/cygwin/bindll.  Then add that bindll directory to your msys path.  Adding the cygwin bin directory to your msys path will get you cygwin versions of various tools, and will greatly confuse things.  You just need the DLLs so that the compilers can execute; the compiler binary paths are explicitly specified.</p>
<p>There&#8217;s a sample mozconfig inside bug 607975.  You&#8217;ll need to use a relative path to run configure, e.g. &#8220;MOZCONFIG=../../fennec-config ../mozilla-central/configure&#8221;, and you must use mingw make and not pymake to build.  pymake has some weird issues, where it complains that it doesn&#8217;t know how to rebuild dependencies like &#8220;-lzlib&#8221;.  This is likely fixable, because I think this is a magic thing that gnu make special-cases, and something that our build system shouldn&#8217;t do in any case.</p>
<p>Some remaining problems with the build:</p>
<ul>
<li>It&#8217;s not clear why jemalloc hangs without the TLS patch; mwu says he has seen this in other cases, but it&#8217;s consistent here.</li>
<li>Opt builds seem to just draw white; not sure why that is, debug builds work fine.  This should be fixable.</li>
<li>Disabling automatic dependencies means you have to be extra careful if you modify a header file or something that might not get picked up; they have to be disabled because the cygwin compiler will generate paths like &#8220;/cygwin/c/&#8230;&#8221; in the deps file, which the msys make won&#8217;t ever be able to find &#8212; thus causing it to rebuild everything on every build.  This is also fixable, perhaps with a postprocessing step after each compilation.</li>
<li>Would be nice if pymake worked for building speed.</li>
</ul>
<p>This is obviously not a full solution, and VMs are still a lot more stable where builds are concerned, but it&#8217;s at least possible to build Fennec for Android under Win32.  GDB also seems to work fine, though as always, you&#8217;ll want to use the <a href="https://wiki.mozilla.org/Mobile/Fennec/Android#Using_nVidia_version_.28recommended.29">NVIDIA-provided gdb/gdbserver</a> pair, because the one that&#8217;s part of the NDK seems to continue to have issues.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2010/11/01/building-fennec-for-android-under-win32/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Information from Windows Vista/7 Display Driver Resets</title>
		<link>http://blog.vlad1.com/2010/10/12/getting-information-from-windows-vista7-display-driver-resets/</link>
		<comments>http://blog.vlad1.com/2010/10/12/getting-information-from-windows-vista7-display-driver-resets/#comments</comments>
		<pubDate>Tue, 12 Oct 2010 16:41:03 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[crashes]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=339</guid>
		<description><![CDATA[Now that we&#8217;re doing hardware acceleration on all platforms, we&#8217;re touching all sorts of OS components that we haven&#8217;t in the past.  One of those is much closer interaction with the graphics card drivers in your system.  Under Windows Vista and Windows 7, problems in the video driver (or in how we use DirectX/OpenGL) sometimes [...]]]></description>
			<content:encoded><![CDATA[<p>Now that we&#8217;re doing hardware acceleration on all platforms, we&#8217;re touching all sorts of OS components that we haven&#8217;t in the past.  One of those is much closer interaction with the graphics card drivers in your system.  Under Windows Vista and Windows 7, problems in the video driver (or in how we use DirectX/OpenGL) sometimes manifest themselves as a graphics driver rest: your screen flashes, and you have a little popup telling you that your video driver had a problem and was reset. If this happens to you while using one of the Firefox 4 betas or nightly builds, here&#8217;s how you can collect information to help us and the graphics hardware vendor fix the problem.  This only applies to Windows Vista and Windows 7.</p>
<h3>1. Did Firefox recover?</h3>
<p>Immediately after the driver reset, did Firefox recover?  If so, skip this step.  If, however, it&#8217;s not repainting and otherwise seems hung, forcing a crash report can help give us data that we need to figure out why recovery didn&#8217;t happen properly.  To do this, I wrote a tool that forces a hung Firefox to crash in a way that will pop up the crash reporter.  You can download it here: <a href="http://people.mozilla.com/~vladimir/misc/force-firefox-crash.zip">force-firefox-crash.zip</a>.  Just unzip and double click on the .exe, and the current running firefox.exe process will be killed, and you&#8217;ll be presented with the crash reporter.</p>
<p>Submit the report, and after restarting Firefox, type in <strong>about:crashes</strong> in the location bar.  You&#8217;ll want the ID of the top entry in this list for when you file a bug or contact support later.  (You can right click the top link and select &#8220;Copy Link Location&#8221; to grab a link for easy pasting.)</p>
<h3>2. Grab the Driver Crash information</h3>
<p>Select the start menu, and type in &#8220;problem report&#8221; in the search box.  Select <strong>View all problem reports </strong>from the list:</p>
<p style="text-align: center;"><a href="http://blog.vlad1.com/wp-content/uploads/2010/10/wer-view-problem-reports.jpg"><img class="size-full wp-image-341  aligncenter" title="View all problem reports" src="http://blog.vlad1.com/wp-content/uploads/2010/10/wer-view-problem-reports.jpg" alt="" width="409" height="321" /></a></p>
<p>In the problem reports list, scroll down to the Windows section if it&#8217;s not visible, and sort by Date &#8212; you want the latest &#8220;Video hardware error&#8221; entry:</p>
<p style="text-align: center;"><a href="http://blog.vlad1.com/wp-content/uploads/2010/10/wer-2.png"><img class="size-full wp-image-342  aligncenter" title="Video hardware error" src="http://blog.vlad1.com/wp-content/uploads/2010/10/wer-2.png" alt="" width="400" height="273" /></a></p>
<p>Double-click on the latest &#8220;Video hardware error&#8221; entry.  In the details screen, click &#8220;View a temporary copy of these files&#8221;:</p>
<p style="text-align: center;"><a href="http://blog.vlad1.com/wp-content/uploads/2010/10/wer-3.png"><img class="size-full wp-image-343  aligncenter" title="Temporary Copy" src="http://blog.vlad1.com/wp-content/uploads/2010/10/wer-3.png" alt="" width="400" height="320" /></a></p>
<p>You&#8217;ll get a new explorer window with three files.  Select all three, and compress them into a ZIP file, by right-clicking and selecting &#8220;Send To -&gt; Compressed Folder&#8221;:</p>
<p style="text-align: center;"><a href="http://blog.vlad1.com/wp-content/uploads/2010/10/wer-4.jpg"><img class="size-full wp-image-344  aligncenter" title="wer-4" src="http://blog.vlad1.com/wp-content/uploads/2010/10/wer-4.jpg" alt="" width="400" height="261" /></a></p>
<p>Copy the resulting zip file to your desktop, so that you can include it with your report.</p>
<h3>3. Create a bug</h3>
<p>Almost done! In <a href="http://bugzilla.mozilla.org">bugzilla.mozilla.org</a>, create a new bug in the Core product and the Graphics component.  Attach the zip file you created in step two to the report.  If you also created a Firefox crash dump in step one, include a link to it in your bug report.</p>
<p>This should give us and the graphics hardware vendors enough information to track down what the original problem was, so that we can fix it for Firefox 4!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2010/10/12/getting-information-from-windows-vista7-display-driver-resets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fun With Fast JavaScript</title>
		<link>http://blog.vlad1.com/2010/07/30/fun-with-fast-javascript/</link>
		<comments>http://blog.vlad1.com/2010/07/30/fun-with-fast-javascript/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 21:14:18 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[demos]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[perf]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=315</guid>
		<description><![CDATA[Fast JavaScript is a cornerstone of the modern web. In the past, application authors had to wait for browser developers to implement any complex functionality in the browser itself, so that they could access it from script code. Today, many of those functions can move straight into JavaScript itself. This has many advantages for application [...]]]></description>
			<content:encoded><![CDATA[<p>Fast JavaScript is a cornerstone of the modern web.  In the past, application authors had to wait for browser developers to implement any complex functionality in the browser itself, so that they could access it from script code.  Today, many of those functions can move straight into JavaScript itself.  This has many advantages for application authors: there&#8217;s no need to wait for a new version of a browser before you can develop or ship your app, you can tailor the functionality to exactly what you need, and you can improve it directly (make it faster, higher quality, more precise, etc.).</p>
<p><a href="http://blog.vlad1.com/wp-content/uploads/2010/07/2010-06-24_1353.png"><img class="alignleft size-full wp-image-316" title="JavaScript Darkroom" src="http://blog.vlad1.com/wp-content/uploads/2010/07/2010-06-24_1353.png" alt="" width="300" height="238" /></a>Here are two examples that show off what can be done with the improved JS engine and capabilities that will be present in Firefox 4.  The first example shows <a href="http://people.mozilla.com/~vladimir/demos/darkroom/darkroom.html">a simple web-based Darkroom</a> that allows you to perform color correction on an image.  The HTML+JS is around 700 lines of code, not counting jQuery.  This is based on a demo that&#8217;s included with Google&#8217;s Native Client (NaCl) SDK; in that demo, the color correction work is done inside native code going through NaCl.  That demo (originally presented as &#8220;too slow to run in JavaScript&#8221;) is a few thousand lines of code, and involves downloading and installing platform-specific compilers, multiple steps to test/deploy code, and installing a plugin on the browser side.</p>
<p>I get about 15-16 frames per second with the default zoomed out image (around 5 million pixels per second &#8212; that number won&#8217;t be affected by image size) on my MacBook Pro, which is definitely fast enough for live manipulation.  The algorithm could be tightened up to make this faster still.  Further optimizations to the JS engine could help here as well; for example, I noticed that we spend a lot of time doing floating point to integer conversions for writing the computed pixels back to the display canvas, due to how the canvas API specifies image data handling.</p>
<p>The Web Darkroom tool also supports drag &amp; drop, so you can take any image from your computer and drop it onto the canvas to load it.  A long (long!) time ago, back in 2006, I wrote <a href="http://people.mozilla.com/~vladimir/corppr/">an addon called &#8220;Croppr!&#8221;</a>.  It was intended to be used with Flickr, allowing users to play around with custom crops of any image, and then leave crop suggestions in comments to be viewed using Croppr.  It almost certainly doesn&#8217;t work any more, but it would be neat to update it: this time with both cropping and color correction.  Someone with the addon (perhaps a <a href="https://jetpack.mozillalabs.com/">Jetpack</a> now!) could then visit a Flickr photo and experiment, and leave suggestions for the photographer.</p>
<p><a href="http://blog.vlad1.com/wp-content/uploads/2010/07/2010-06-24_1352.png"><img class="alignright size-full wp-image-318" title="JavaScript Video FFT" src="http://blog.vlad1.com/wp-content/uploads/2010/07/2010-06-24_1352.png" alt="" width="350" height="425" /></a>The <a href="http://people.mozilla.com/~vladimir/demos/jsfft/jsfft.html">second example</a> is based on some work that Dave Humphrey and others have been doing to bring audio manipulation to the web platform.  Originally, their spec included a pre-computed FFT with each audio frame delivered to the web app.  I suggested that there&#8217;s no need for this &#8212; while a FFT is useful for some applications, for others it would be wasted work.  Those apps that want a FFT could implement one in JS.  Some benchmark numbers backed this up &#8212; using the <a href="https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/doc/spec/TypedArray-spec.html">typed arrays</a> originally created for <a href="http://webgl.org/">WebGL</a>, computing an FFT in JS was approaching the speed of native code.  Again, both could be sped up (perhaps using SSE2 or something like Mono.Simd on the JS side), but it&#8217;s fast enough to be useful already.</p>
<p>The demo shows this in action.  A numeric benchmark isn&#8217;t really all that interesting, so instead I take a video clip, and as it&#8217;s playing, I extract a portion of the green channel of each frame and compute its 2D FFT, which is then displayed.  The original clip plays at 24 frames per second, so that&#8217;s the upper bound of this demo.  Using Float32 typed arrays, the computation and playback proceeds at around 22-24fps for me.</p>
<p>You can grab the video controls and scrub to a specific frame.  (The frame rate calculation is only correct while the video is playing normally, not while you&#8217;re scrubbing.)  The video source uses Theora, so you&#8217;ll need a browser that can play Theora content.  (I didn&#8217;t have a similar clip that uses WebM, or I could have used that.)</p>
<p>These examples are demonstrating the strength of the trace-based JIT technique that Firefox has used for accelerating JavaScript since Firefox 3.5.  However, not all code can see such dramatic speedups from that type of acceleration.  Because of that, we&#8217;ll be including a full method-based JIT for Firefox 4 (for more details, see <a href="http://www.bailopan.net/blog/?p=683">David Anderson&#8217;s blog</a>, as well as <a href="http://blog.mozilla.com/dmandelin/2010/05/10/jm-halfway/">David Mandelin&#8217;s blog</a>).  This will provide significantly faster baseline JS performance, with the trace JIT becoming a turbocharger for code that it would naturally apply to.</p>
<p>Combining fast JavaScript performance alongside new web platform technologies such as WebGL and Audio will make for some pretty exciting web apps, and I&#8217;m looking forward to seeing what developers do with them!</p>
<p><em>Edit: Made some last-minute changes to the demos, which ended up pulling in a slightly broken version of jQuery UI that wasn&#8217;t all that happy with Safari.  Should be fixed now!</em></p>
<p><em>Edit #2: This <a href="http://www.movavi.com/opensource/fun-with-fast-javascript-be">post is available in Belorussian</a>, courtesy of Jason Fragoso!</em><a href="http://www.movavi.com/opensource/fun-with-fast-javascript-be" target="_blank"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2010/07/30/fun-with-fast-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Losing My Memory</title>
		<link>http://blog.vlad1.com/2010/05/10/losing-my-memory/</link>
		<comments>http://blog.vlad1.com/2010/05/10/losing-my-memory/#comments</comments>
		<pubDate>Mon, 10 May 2010 21:47:59 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[jemalloc]]></category>
		<category><![CDATA[memory]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=296</guid>
		<description><![CDATA[With the work going on to bring Firefox to mobile devices, and with desktop users demanding more and more from their web browser, memory usage is a concern.  Even with 4GB on desktop and laptops becoming commonplace, and 8GB, 12GB, 16GB etc. becoming not all that unusual, it&#8217;s unnerving to see a web browser eating [...]]]></description>
			<content:encoded><![CDATA[<p>With the work going on to bring Firefox to mobile devices, and with desktop users demanding more and more from their web browser, memory usage is a concern.  Even with 4GB on desktop and laptops becoming commonplace, and 8GB, 12GB, 16GB etc. becoming not all that unusual, it&#8217;s unnerving to see a web browser eating up a large chunk of that.  I&#8217;ve been spending time figuring out how we can improve our memory usage, which starts with finding out where Firefox uses memory to begin with.</p>
<p>Let&#8217;s get one thing out of the way up front.  Today&#8217;s web browser is in many ways acting like a miniature full operating system.  It runs multiple applications at once (whether in multiple windows or tabs).  It might do a lot of background processing.  It can work with large data sets, for example large images on flickr or large spreadsheets on Google Documents.  But, the final memory usage number that the user sees when they open up the Task Manager or Process Viewer is the aggregate memory usage of the entire system.  So, the goal of improving our memory usage is not to get that number to the lowest possible &#8212; doing that would be an unacceptable tradeoff in performance for users &#8212; but instead to understand where memory is being used, and then use that data to improve in those areas as possible.</p>
<p>One comment that I&#8217;ve heard is that Firefox 3.6 seems to use more memory than Firefox 3.0.  My initial tests show this to not be true; specifically, I looked at the &#8220;Private Bytes&#8221; value in the Windows 7 task manager shortly after startup with about:blank, and also after opening a number of tabs (gmail, google docs, cnn.com, front page of the boston.com big picture blog, engadget, and a few others).  Here are the results of a typical run:</p>
<p><center><br />
<table style="border: 1px solid black;">
<tr>
<th>(in kb)</th>
<th>Firefox 3.0</th>
<th>Firefox 3.6</th>
</tr>
<tr>
<th>Blank Page</th>
<td align="right">20,052</td>
<td align="right">21,740</td>
</tr>
<tr>
<th>Multiple Tabs</th>
<td align="right">115,532</td>
<td align="right">109,128</td>
</tr>
</table>
<p></center></p>
<p>The next question is figuring out where all the memory goes.  I&#8217;ve been adding some instrumentation to Firefox to figure out in more detail where memory is being used.  For a sample run with the multiple tabs shown above, here&#8217;s what some of that reporter data looks like:</p>
<p><center><br />
<table style="border: 1px solid black;">
<tr>
<th>Component</th>
<th>Memory (in kb)</th>
<tr>
<th align="left">Windows &#8211; Private Bytes</th>
<td align="right">111,616</td>
</tr>
<tr>
<th align="left">jemalloc &#8211; Commit Size</th>
<td align="right">91,684</td>
</tr>
<tr>
<th align="left">JavaScript &#8211; GC Chunks</th>
<td align="right">11,534</td>
</tr>
<tr>
<th align="left">JavaScript &#8211; NJ Trace Code</th>
<td align="right">128</td>
</tr>
<tr>
<th align="left">JavaScript &#8211; js_malloc Other</th>
<td align="right">30,142</td>
</tr>
<tr>
<th align="left">Images (uncompressed)</th>
<td align="right">53,811</td>
</tr>
<tr>
<th align="left">Graphics Surfaces (win32)</th>
<td align="right">53,967</td>
</tr>
<tr>
<th align="left">PresShell Arenas</th>
<td align="right">6,373</td>
</tr>
</table>
<p></center></p>
<p>Or, graphically:</p>
<p><center><a href="http://blog.vlad1.com/wp-content/uploads/2010/05/foo.png"><img src="http://blog.vlad1.com/wp-content/uploads/2010/05/foo.png" alt="" title="Memory Usage Sample" width="600" height="216" class="aligncenter size-full wp-image-305" /></a></center></p>
<p>There&#8217;s some overlap in those numbers &#8212; for example, the jemalloc commit size is a subset of the Windows Private Bytes number, and most of the rest is a subset of the jemalloc commit size.  Likewise, the uncompressed images number is a subset of the Win32 graphics surfaces number; that is, ~53MB is in use by win32 surfaces, and almost all of that is due to live images in pages (remember that we&#8217;ve got some image heavy sites in that tab set, including the Big Picture blog which has around 10-11 large images on it&#8230; those should account for about 20-25MB just by themselves).</p>
<p>There are some things that don&#8217;t make sense in the above, which mean that my instrumentation isn&#8217;t quite correct&#8230; for example, adding up the JS numbers, the Images number, and the PresShell arenas number brings us beyond the jemalloc commit size, which shouldn&#8217;t be true.  However, some of the Image data is allocated by GDI, likely bypassing jemalloc, so we have to take that into account.  There&#8217;s also some large other chunks of the browser that have yet to be instrumented, which should provide additional insight.</p>
<p>Two initial observations: one, keeping images compressed in memory and only decompressing them briefly when we need to draw them is a potential huge memory win.  We have the infrastructure and code to do this in place; it was disabled recently while some of the internals changed, and it needs to be reenabled.</p>
<p>Two, the 30MB or so in the &#8220;js_malloc Other&#8221; bucket is also pretty curious.  We need to do some more work to figure out what exactly is in here.  (This contains things like data structures for tracking array contents and &#8212; potentally a big one &#8212; string data.)</p>
<p>I&#8217;ll be blogging more as the instrumentation takes shape, and as it gets landed into trunk nightly builds.  Much of this information will be visible in about:memory, and eventually we&#8217;ll be able to give some per-tab memory information as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2010/05/10/losing-my-memory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fennec on Android</title>
		<link>http://blog.vlad1.com/2010/04/27/fennec-on-android-ground-zero/</link>
		<comments>http://blog.vlad1.com/2010/04/27/fennec-on-android-ground-zero/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 00:39:39 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=280</guid>
		<description><![CDATA[Over the last few months, we&#8217;ve made some great progress on bringing Firefox to Android.  Michael Wu, Brad Lassey, Alex Pakhotin and I have been focusing on getting a build ready that&#8217;s usable by a broader set of people, and we&#8217;re now ready to get that build out there.  This build should be considered &#8220;pre-alpha&#8221;, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.vlad1.com/wp-content/uploads/2010/04/fennec-n1.png"><img class="alignright size-full wp-image-286" title="fennec-n1" src="http://blog.vlad1.com/wp-content/uploads/2010/04/fennec-n1.png" alt="" width="240" height="400" /></a>Over the last few months, we&#8217;ve made some great progress on bringing Firefox to Android.  Michael Wu, Brad Lassey, Alex Pakhotin and I have been focusing on getting a build ready that&#8217;s usable by a broader set of people, and we&#8217;re now ready to get that build out there.  This build should be considered &#8220;pre-alpha&#8221;, so there are some warnings and caveats:</p>
<ul>
<li>We&#8217;ve only really tested this on the Motorola Droid and the Nexus One.</li>
<li>It will likely not eat your phone, but bugs might cause your phone to stop responding, requiring a reboot.</li>
<li>Memory usage of this build isn&#8217;t great &#8212; in many ways it&#8217;s a debug build, and we haven&#8217;t really done a lot of optimization yet.  This could cause some problems with large pages, especially on low memory devices like the Droid.</li>
<li>You&#8217;ll see the app exit and relaunch on first start, as well as on add-on installs; this is a quirk of our install process, and we&#8217;re working to get rid of it.</li>
<li>You can&#8217;t open links from other apps using Fennec; we should have this for the next build.</li>
<li>This build requires Android 2.0 or above, and likely an OpenGL ES 2.0 capable device.</li>
<li>Edit: This build must be installed to internal memory, not to a SD card.</li>
</ul>
<p>There also aren&#8217;t yet any automated nightly developer builds or automated updates to this build; it&#8217;s even more of a pre-nightly build (even earlier than pre-alpha).  But, it&#8217;s usable enough that we wanted to get some feedback on it as we continue to develop.</p>
<h3>Weave Sync</h3>
<p>There is an experimental version of Weave that is compatible with this build: from within Fennec on your phone, open the Mozilla Labs weave page at <a href="https://mozillalabs.com/weave/">https://mozillalabs.com/weave/</a> and click on &#8220;Experimental Version&#8221;.  (It&#8217;s to the right of the big <em>Download Weave now!</em> link &#8212; don&#8217;t click on that one though, it&#8217;s an older version.)  Install the add-on, then you&#8217;ll need to restart Fennec (swipe the screen left and then click on the &#8220;gear&#8221; icon to open the browser tools panel, then click on addons and click the Restart button at the top).  Follow the instructions when Fennec restarts.</p>
<h3>Troubleshooting</h3>
<p>Should you run into problems, such as the app not responding or just giving you a black screen, you can force it to quit by going into the Android Settings, selecting Applications, selecting Manage Applications, then selecting Fennec, and tapping Force Stop.  (A utility called <em>White Killer</em>, available from the Market, can do the same job with fewer clicks.)  Worst case, uninstalling and reinstalling would clear out your profile and any saved data.</p>
<h3>Installation &amp; Feedback</h3>
<p><a href="http://bit.ly/fennec-android"><img class="alignleft size-full wp-image-283" title="Fennec for Android QR" src="http://blog.vlad1.com/wp-content/uploads/2010/04/fennec-android-bitly.png" alt="" width="155" height="155" /></a>So, now that you&#8217;ve read all that, you can <a href="http://bit.ly/fennec-android">download the build here</a> &#8212; the easiest way is to download it using your phone&#8217;s browser, and then click on it in the downloads list to install it.  If you&#8217;re reading this on your desktop, you can scan the QR code here on your phone, or type in the following address in your phone&#8217;s browser: <strong>bit.ly/fennec-android</strong>.  You may need to enable installation of non-Market applications by going to Settings, Applications, and checking &#8220;Unknown Sources&#8221;.</p>
<p>We&#8217;ve created a temporary <a href="http://groups.google.com/group/fennec-android-pre-alpha">Google Group for feedback</a> about this pre-alpha build.  In the future we&#8217;ll have a more permanent way for user feedback and comments, but for now, please use the group to let us know what you think!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2010/04/27/fennec-on-android-ground-zero/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Three Fennecs, All in a Row</title>
		<link>http://blog.vlad1.com/2010/03/19/three-fennecs-all-in-a-row/</link>
		<comments>http://blog.vlad1.com/2010/03/19/three-fennecs-all-in-a-row/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 00:11:19 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[fennec]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=268</guid>
		<description><![CDATA[After wrestling with OpenGL on Android for a bit, I was finally able to get Gecko on Android rendering using OpenGL.  This was needed to both simplify the build process, removing the need to have private Android headers and libraries available, and also to remove an expensive CPU RGB-&#62;BGR byte swap.  Michael Wu&#8217;s also done [...]]]></description>
			<content:encoded><![CDATA[<p>After <a href="http://blog.vlad1.com/2010/03/19/things-i-learned-today-android-opengl-edition-2/">wrestling with OpenGL</a> on Android for a bit, I was finally able to get Gecko on Android rendering using OpenGL.  This was needed to both simplify the build process, removing the need to have private Android headers and libraries available, and also to remove an expensive CPU RGB-&gt;BGR byte swap.  Michael Wu&#8217;s also done a pile of work, including the all-important keyboard hookup so that you can, you know, type in some URLs or search terms.  (Handy in a web browser.)  Here&#8217;s a little family portrait of Fennec running on a Nexus One, a Motorola Droid, and a display attached to a NVIDIA Tegra 250 devkit.</p>
<p style="text-align: center;"><a href="http://blog.vlad1.com/wp-content/uploads/2010/03/three-fennecs.jpg"><img class="aligncenter wp-image-269" title="three-fennecs" src="http://people.mozilla.com/~vladimir/misc/three-fennecs.jpg" alt="" width="626" height="470" /></a></p>
<p>We&#8217;re still working on getting the basic blocks in place to where it&#8217;s &#8220;dogfoodable&#8221;, that is, usable by the developers.  The good news is that while the builds are already pretty fast, we&#8217;re seeing that we have a <em>lot</em> of headroom for performance&#8230; especially for visual things like rendering and panning.  Most of the work we&#8217;ve done so far has just been quick work to unblock getting the basic port running; I&#8217;m looking forward to being able to dig deeper into a bunch of these issues!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2010/03/19/three-fennecs-all-in-a-row/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Things I Learned Today: Android OpenGL Edition</title>
		<link>http://blog.vlad1.com/2010/03/19/things-i-learned-today-android-opengl-edition-2/</link>
		<comments>http://blog.vlad1.com/2010/03/19/things-i-learned-today-android-opengl-edition-2/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 23:58:04 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[gecko]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[opengl es]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=262</guid>
		<description><![CDATA[One of the issues with the Gecko port to Android is that, early on, I used some internals to tie in to the Android graphics system from native code.  This worked fine, but it complicated the build: you needed to pull in a bunch of headers and some libraries from the actual Android source to [...]]]></description>
			<content:encoded><![CDATA[<p>One of the issues with the Gecko port to Android is that, early on, I used some internals to tie in to the Android graphics system from native code.  This worked fine, but it complicated the build: you needed to pull in a bunch of headers and some libraries from the actual Android source to be able to complete a build.</p>
<p>The solution for this was pretty easy: move to OpenGL for rendering.  However, there are some interesting quirks here.  I&#8217;m targeting Android 2.x only: specifically the Motorola Droid, HTC Nexus One, and a NVIDIA Tegra 250 devkit I have here.  For this initial step, all I need is to just draw a textured quad.  We&#8217;ve got full OpenGL compositing, rendering, fancy video decoding and all that stuff coming later, but for now we&#8217;re just hooking into our software rasterizer, uploading the result as a texture, and drawing a textured quad.  Easy, right?  Here are some random issues I ran into while doing this over the past day or two.</p>
<h3>First Attempt: OpenGL ES 1.1</h3>
<p>Well, there are two wrinkles.  First, Cairo&#8217;s software rasterizer uses a 32-bit ARGB pixel format and layout.  In little-endian per-byte terms, that&#8217;s B G R A.  OpenGL ES supports A R G B.  There is an EXT_bgra extension that adds support for GL_BGRA as another byte format, and this extension is one that&#8217;s potentially available on GL ES.  The second wrinkle is that this quad is display-sized, so the texture is display sized; it&#8217;s not going to be power-of-two dimensions.  While OpenGL ES 2.0 supports non power of two textures in the base (with some limitations, which are not relevant for my use case), ES 1.1 does not, and I figured given that all I was drawing is a textured quad, I may as well use ES 1.1.</p>
<p>Unfortunately, the tree devices I mentioned above support different combinations of these.  The NVIDIA device supports both EXT_bgra and ARB_texture_non_power_of_two.  This is perfect; no workarounds are needed here, though for some reason it doesn&#8217;t like TexSubImage2D with BGRA data, but that&#8217;s not a big deal.  The Droid (OMAP3, PowerVR SGX) supports EXT_texture_format_BGRA8888 (note: different name, similar functionality), so that&#8217;s good, but it doesn&#8217;t support non power of two textures with ES1.1.  The Nexus One, on the other hand, supports neither BGRA nor NPOT textures.</p>
<p>I was about to start using OES_draw_texture as well, because that seemed like a potentially faster way to get what I want to happen &#8212; but the lack of BGRA support on the Nexus One made me turn to ES2, where I can do the RGBA-&gt;BGRA swizzle in the fragment shader.</p>
<h3>Undefined Symbols in GLESv2 Import Library</h3>
<p>More fun!  The Android r3 NDK includes GLESv2 support, yay!  The bad news is that libGLESv2.so includes an external reference to _ZN7android33egl_get_image_for_current_contextEPv (android::egl_get_image_for_current_context), which means you&#8217;ll get linker errors (or at least undefined symbol errors) if you try to link anything that&#8217;s not a shared library.  Conveniently, that&#8217;s what you need to produce with the NDK anyway, but if you have some helper command line tools along the way, they&#8217;ll fail.  The solution is to add -Wl,&#8211;allow-shlib-undefined to your binary compile/link step.</p>
<p>After that, this was fairly straightforward, though the SDK only grudgingly allows you to specify the necessary EGL tokens for GLES2; the code samples in the NDK all just provide explicit integer values for them inside the code.</p>
<h3>Choosing an EGLConfig</h3>
<p>This applies to both OpenGL ES 1 and OpenGL ES 2 on Android.  When creating an EGLSurface for a SurfaceView (take a look at how GLSurfaceView does it for the details), you have to get an EGLConfig that has an exact match for the number of red/green/blue/alpha bits as your surface.  There&#8217;s a format parameter to surfaceChanged that&#8217;s supposed to tell you the format of the surface.  However, it seems to always show up as &#8216;-1&#8242;, which according to PixelFormat.java, is &#8220;OPAQUE&#8221;.  That&#8217;s not very helpful.  Reading GLSurfaceView, it can show up as -2, which is TRANSPARENT.  So &#8212; you have to assume that if you have an OPAQUE surface format, it&#8217;ll be 5650, and if you have a TRANSPARENT format it&#8217;ll be 8888.  This is pretty silly, as there are PixelFormat constants for handy things like RGBA_8888, RGB_565, RGB_888, RGBA_5551, etc.  Why doesn&#8217;t SurfaceView send the actual format down?</p>
<p>The devices that I have seem pretty consistent at least with 565 for OPAQUE, so it works OK, but it&#8217;s not pretty, and will likely blow up spectacularly if anyone introduces, say, a large-display Android device that uses 24bpp color.</p>
<p>Another config issue is that some GPUs have some odd requirements for getting the most preformance; for example, as discovered via searching, the PowerVR SGX in the Droid really wants 24-bit depth, as it&#8217;s faster than 0 and 32.  The Tegra, on the other hand, doesn&#8217;t have 24bpp depth at all, only 0 or 16 (and I don&#8217;t think it cares one way or the other).  Not sure whether the GPU in the Nexus One cares or has a preference.  So, you have to search for a 24-bit depth config first, use it if it&#8217;s found, and then try 0 if not found.  I suppose an alternate approach might be to search for 16-bit depth, but that might give you 32-bit if that happens to be supported somewhere.</p>
<p>At the end of all of this though, I have an app that uses OpenGL ES 2 on three different Android devices (with three different GPUs).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2010/03/19/things-i-learned-today-android-opengl-edition-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using a Caching Proxy Server for Web Demos</title>
		<link>http://blog.vlad1.com/2010/03/15/using_a_caching_proxy_server/</link>
		<comments>http://blog.vlad1.com/2010/03/15/using_a_caching_proxy_server/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 21:59:33 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[demos]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=260</guid>
		<description><![CDATA[A while ago, Rob Arnold wrote a simple python caching proxy server for use with our Talos tests &#8212; the idea was that you&#8217;d run your test once against the proxy server in &#8220;record&#8221; mode, and then after that you can use the server for consistent local playback. I was giving some WebGL demos recently, [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago, Rob Arnold wrote a simple python caching proxy server for use with our Talos tests &#8212; the idea was that you&#8217;d run your test once against the proxy server in &#8220;record&#8221; mode, and then after that you can use the server for consistent local playback.</p>
<p>I was giving some WebGL demos recently, and needed a way to have all the content from the web-hosted demos locally.  As anyone who&#8217;s tried to create a local cache of any &#8220;Web 2.0&#8243; app knows, it&#8217;s painful, given all the server requests, XMLHttpRequests, etc. that go on.  However, with the proxy server, this was actually ridiculously easy.</p>
<p>You can grab the proxy server here &#8212; it still lives in Mozilla CVS &#8212; <a href="http://mxr.mozilla.org/mozilla/source/testing/tools/proxyserver/proxyserver.py?raw=1">proxyserver.py</a>.  It works fine on Win32, OS X, and Linux.  On Win32, the python that&#8217;s part of mozilla-build works well.  Run it like this:</p>
<pre>python proxyserver.py</pre>
<p>and then in Firefox&#8217;s proxy settings (or the system proxy settings), set your HTTP proxy to <strong>localhost:8000</strong>.  You can change the port via a command line option.  Then, visit all the pages/sites that you want cached (don&#8217;t forget to shift-reload or clear Firefox&#8217;s cache beforehand to ensure that Firefox actually goes out to the network!).  After you&#8217;ve got everything going, restart the proxy server in local-only mode:</p>
<pre>python proxyserver.py -l</pre>
<p>&#8230; and make sure that your demos work.  You can also run without -l live, especially if you will have a network connection (even a slow one) to give you the option of going out to the network if necessary.  Also, if you want to copy the proxy cache to another machine, just copy <strong>proxy_cache.db </strong>that gets created in the same directory as proxyserver.py.</p>
<p>The proxy server currently supports HEAD and GET requests.  It doesn&#8217;t support POST, so if you have something that depends on POST, you&#8217;re out of luck.  It wouldn&#8217;t be too hard to add though; patches accepted if someone wants to tackle that.</p>
<p>With the proxy server, I was able to give a bunch of demos that made heavy use of XHR, including some that loaded video, without having to rely on a network or spend time downloading and fixing up URLs.  It really made demo prep much easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2010/03/15/using_a_caching_proxy_server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>mjs: Simple Vector and Matrix Math for JS</title>
		<link>http://blog.vlad1.com/2010/02/05/mjs-simple-vector-and-matrix-math-for-js/</link>
		<comments>http://blog.vlad1.com/2010/02/05/mjs-simple-vector-and-matrix-math-for-js/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 09:04:19 +0000</pubDate>
		<dc:creator>vladimir</dc:creator>
				<category><![CDATA[Canvas 3D]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[spidermonkey]]></category>
		<category><![CDATA[webgl]]></category>

		<guid isPermaLink="false">http://blog.vlad1.com/?p=253</guid>
		<description><![CDATA[One common thread running through the many different and interesting WebGL projects out there is that they all need to do vector and matrix math, do it quickly, and do it in JavaScript.  To date, developers have either rolled their own, or they&#8217;ve used Sylvester, a fairly featureful vector and matrix JavaScript library. One of [...]]]></description>
			<content:encoded><![CDATA[<p>One common thread running through the <a href="http://learningwebgl.com/blog/">many</a> <a href="http://www.c3dl.org/">different</a> and <a href="http://www.glge.org/">interesting</a> <a href="http://www.webgl.org/">WebGL</a> <a href="http://www.x3dom.org/">projects</a> out there is that they all need to do vector and matrix math, do it quickly, and do it in JavaScript.  To date, developers have either rolled their own, or they&#8217;ve used <a href="http://sylvester.jcoglan.com/">Sylvester</a>, a fairly featureful vector and matrix JavaScript library.</p>
<p>One of the problems with Sylvester is that while it&#8217;s fully featured (arbitrary NxN matrices and vectors can be created and manipulated), it suffers in performance because of it.  Since this is such a crucial part of a successful WebGL program, I&#8217;ve put together a small package that I&#8217;m calling <strong>mjs</strong>.</p>
<p><strong>mjs</strong> is designed around speed and simplicity.  For example, it doesn&#8217;t attempt to stuff vectors and matrices into JavaScript objects.  Because the language offers no operator overloading, there&#8217;s very little benefit in treating these types as discrete objects, and lots of performance and memory usage downsides.  Instead, it provides a set of functions for performing operations on vectors and matrices, which can be any array-like object.  For any function that returns a vector or matrix, an existing array can be passed in to take the result, or the function can create a new one.  Array reuse ends up being important because of the potential for expensive garbage collection churn eating away at performance.</p>
<p>Here&#8217;s a sample of the API:</p>
<pre>var r = M4x4.rotate(Math.PI/2, V3.$(0, 1, 0),  M4x4.I);</pre>
<p>Note that V3.$ and M4x4.$ are shorthand for creating a new V3 or M4x4 (I wanted to use V3() and M4x4(), but that didn&#8217;t work out too well since functions have a length property).  However, because all they return are just new array-like objects, you could also write:</p>
<pre>var r = M4x4.rotate(Math.PI/2, [0, 1, 0], M4x4.I);</pre>
<p>If the WebGL types are available, those will be used for newly created vectors/matrices.  They are a significant performance boost especially for repeated operations; but for specifying one-off vectors such as the above, literal array syntax is fine.</p>
<p>The rotate function internally makes a rotation matrix, and then multiplies it by the given matrix.  So the above could also be written as:</p>
<pre>var rotation = M4x4.makeRotate(Math.PI/2, [0, 1, 0]);
var r = M4x4.mul(M4x4.I, rotation);</pre>
<p>(The last line being redundant given that we&#8217;re multiplying by the identity matrix.)</p>
<p>All methods that return a vector or matrix take an optional final argument, that of an existing object to reuse.  For example:</p>
<pre>var m0 = M4x4.$();
r = M4x4.mul(someMatrixA, someMatrixB, m0);
// r == m0, so the assignment isn't necessary, but it's handy for chaining
// .... do something with r ...
r = M4x4.mul(someMatrixB, someMatrixC, m0);
// r == m0 still
// ... do something else with new results ...</pre>
<p>Without allocating any additional temporary objects.</p>
<p>As mentioned before, one of the goals of <strong>mjs</strong> is performance.  Matrix multiplication is one of the most common tasks, so here are some numbers comparing <strong>mjs</strong>, Sylvester, and native C code.  This was run on a Core i7 desktop using a local build of Spidermonkey, which included one patch that&#8217;s about to go into the tree that fixes the no-reuse tracing case.  (Without it, the no-reuse tracing case is much larger because it&#8217;s never actually jitted.)  The test is simple: it multiplies two matrices together in a loop 1,000,000 times.</p>
<table>
<tr>
<th>Test</th>
<th>Time</th>
</tr>
<tr>
<td>mjs, JIT, matrix reuse</td>
<td align="right">140ms</td>
</tr>
<tr>
<td>mjs, JIT, no reuse</td>
<td align="right">533ms</td>
</tr>
<tr>
<td>Sylvester, JIT, no reuse</td>
<td align="right">5,280ms</td>
</tr>
<tr>
<td>mjs, no JIT, matrix reuse</td>
<td align="right">25,833ms</td>
</tr>
<tr>
<td>mjs, no JIT, no reuse</td>
<td align="right">26,681ms</td>
</tr>
<tr>
<td>Sylvester, no JIT, no reuse</td>
<td align="right">41,996ms</td>
</tr>
<tr>
<td>Native C++, SSE2, matrix reuse</td>
<td align="right">71ms</td>
</tr>
<tr>
<td>Native C++, SSE2, no reuse</td>
<td align="right">142ms</td>
</tr>
</table>
<p>(I also have numbers for MSVC without the SSE2 compile flag, but the numbers vary greatly depending on whether the values eventually go to infinity or not; if the values end up trending towards 0, the non-SSE2 code tends to win at around 52ms vs. 71ms; if the values trend to infinity, the non-SSE2 code takes around 11,000ms!)</p>
<p>Those numbers are pretty encouraging &#8212; having native code be only 2x as slow for something like this is pretty nice to see.  Granted, this is only a very isolated test, and I&#8217;m sure there are some tricks to optimizing the native code case (it&#8217;s currently just a fully unrolled set of multiplies and adds).  The &#8220;no JIT&#8221; case is less nice, but I&#8217;m sure that our Jaegermonkey folks will be all over this testcase (right, guys?).  In any case, ideally most WebGL rendering loops will be fully traced in Firefox, so it would be less of an issue.</p>
<p><strong>mjs</strong> is still very much a work in progress; it&#8217;s missing a test suite and a whole bunch of features.  You can find it hosted at Google Code, at <a href="http://webgl-mjs.googlecode.com/">webgl-mjs</a>.  (Side note: I couldn&#8217;t just call the project mjs because a project called mjs was abandoned on Sourceforget 5 years ago, and Google Code complained.)  There&#8217;s also some documentation, <a href="http://webgl-mjs.googlecode.com/hg/docs/files/mjs-js.html">viewable online here</a>.</p>
<p>Bugs and contributions welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vlad1.com/2010/02/05/mjs-simple-vector-and-matrix-math-for-js/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

