OpenLaszlo 4.2 adds SWF9 Support

In case you missed it among the holiday cheer, OpenLaszlo 4.2 was officially released last week. Personally, I’ve been looking forward to this release for a while, since it adds support for SWF9. SWF9 is bytecode that’s optimized for the Flash Player 9 runtime. Flash developers may know it as ActionScript 3 (AS3). The exciting thing for OpenLaszlo developers is that SWF9 is vastly faster than SWF8. And since Flash Player 9 is widely-deployed, you can start using it as the default runtime for new applications.

SWF9 support may not sound like a huge deal to many people – it’s just a matter of keeping up-to date with the newer version of Flash, isn’t it? Well, not exactly. The difference between SWF8 bytecode and SWF9 bytecode was significant. So big, in fact, that Adobe included two completely separate runtimes in Flash Player 9: one for running the new SWF9 bytecode, and a separate one for running SWF8-and-below bytecode. In other words, the SWF9 capability is a pretty big deal.

Just how much of a performance gain does the new runtime offer? A few months ago, while writing a post about optimizing data for Lzx (OpenLaszlo Performance Tip: Attributes, not Nodes), I found that the then-beta SWF9 runtime in OpenLaszlo was as much as 3.7 times faster than the SWF8 one, at loading and parsing XML data. At the time, much of the functionality was still missing from the 4.2 branch, so data loading was the only behavior I could test.

With 4.2 available, I wrote a simple test that measured how long it took to instantiate 100 windows:


    <text id="output" fontsize="36" />

    <class name="mywindow" extends="window" width="300" height="200">

    <handler name="oninit"><![CDATA[
        var dStart = new Date();
        var j:Number = 0;
        var xpos:Number;
        var ypos:Number;

        for (j=0; j<100; j++) {
            xpos = Math.max(150, Math.random() * canvas.width);
            ypos = Math.max(50, Math.random() * canvas.height);
            new lz.mywindow(canvas, {x: xpos, y: ypos});
        var dEnd = new Date();
        var timeTaken = dEnd.getTime() - dStart.getTime();
        output.setAttribute("text", timeTaken);

The results for creating 100 windows in OpenLaszlo 4.2.0 are:

  • SWF8: 6,042ms
  • SWF9: 1,073ms

That’s 5.6 times faster – even more dramatic than the results from the data loading test!

Surely all OpenLaszlo developers will now rush to recompile their applications to SWF9; all it takes is appending ?lzt=swf9 to the request, doesn’t it? Unfortunately, it’s not that simple. Moving from OpenLaszlo 4.0 to 4.1 involved a lot of language changes, specifically in anticipation of SWF9. I wrote about this a while back. Then, moving from OpenLaszlo 4.1 to 4.2, there were a few more changes, mainly because icompatibilities were found after 4.1 had been released, and in-depth development had started on supporting the new runtime. As an example, the <script> tag shouldn’t be used in SWF9. It actually partly works, but causes confusing errors. Better replace it with <handler name=”oninit”>.

Happily there are some resources and tools for developers needing to migrate their applications. There’s an OpenLaszlo wiki page on Runtime Differences, which should be your first stop. It describes how to use the Perl migration script that (in theory) updates your code for you. Remember that it may not catch everything. It’s hard to anticipate every manner in which developers will use a platform, so please be patient and provide any feedback on issues you hit on the forums or mailing lists.

Leave a Reply

Your email address will not be published. Required fields are marked *