Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


Using Runtime Shared Libraries
Improving download performance

With Macromedia Flex 1.5 you can build runtime shared libraries (RSLs) that can be individually loaded, cached, and used by multiple applications. This article demonstrates how easily you can integrate RSLs into your Flex applications. It also addresses the performance tradeoffs that you must consider when building dynamically linked applications.

The Basics
The best way for you to learn about RSLs is to build several copies of the same application with and without various permutations of RSL settings. Follow these steps:

1.  Create Info.mxml, a small MXML component that displays its initialization time:

<?xml version="1.0" encoding="iso-8859-1"?>
<mx:Button xmlns:mx="http://www.macromedia.com/2003/mxml"
backgroundColor="#ffffff"
width="250" height="150"
initialize="go()">
<mx:Script>
var name:String = "?";
function go()
{
var start:Number = 0;
if (_global.startTime != undefined)
start = _global.startTime;

var dt:Number = (getTimer() - start) / 1000;
label = name + " initialized in " + dt + " s." ;
}
</mx:Script>
</mx:Button>

2.  Create app1.mxml, a trivial little application that you use as the basis for the experiments:

<?xml version="1.0" encoding="iso-8859-1"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
xmlns="*"
width="300" height="200">
<Info name="{className}" />
</mx:Application>

3.  Load app1.mxml in your browser. You will see a button similar to Figure 1.

Figure 1. Browsing app1.mxml, a simple Flex application

The size of the generated SWF file is fairly large, because simply using the Application and Button classes causes much of the Flex application model to be linked into your application. If you have the <keep-generated-swfs> option enabled in your Flex configuration file, Flex writes a copy of the SWF file to the application directory as app1.swf (not to be confused with the URL used to download the SWF file, which is actually app1.mxml.swf):

% ls -l app1.swf
-rw------- 1 rg 129899 Oct 18 07:14 app1.swf

Each Flex application starts from a similar baseline size, because each contains most of the same components. Clearly, if you have multiple Flex applications on your server, it is wasteful (of users time and your bandwidth) for users to have to download so much redundant information!

Wouldn't it be nice to factor shared components and assets in your application into libraries that could be loaded at runtime? You can!

The following steps show you how to convert your baseline application to use RSLs: #1  Specify what goes into the library. Create a file named shared.sws with the following content:

<library>
<component name="Application"
uri="http://www.macromedia.com/2003/mxml" />
<component name="Info" uri="*" />
</library>

#2  Copy app1.mxml to app2.mxml. Edit app2.mxml to look like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
xmlns="*"
width="300" height="200"
rsl="shared.sws">
<Info name="{className}" />
</mx:Application>

#3  Load app2.mxml in your browser, and if you haven't made any typos, it should look virtually identical to app1 (Figure 1).

Congratulations, you've now converted a statically linked Flex application (all components and assets defined internally) to a dynamically linked Flex application (some components and assets loaded at runtime). Observe the file sizes:

-rw-------  1 rg    129899 Oct 18 07:14 app1.swf
-rw-------  1 rg    9127 Oct 18 07:23 app2.swf

You've decreased the SWF file size by 117K - quite an improvement! I'll explain where the bits went in the next section. On the surface, it might appear from your SWS file that you were only going to import the Application and Button components. However, you are actually also importing all their dependencies. In general, you will see an immediate improvement in download size by building a SWS file that just references Application, but you get the best improvement by carefully setting up your SWS specification to include all referenced shared components.

Currently, there is no straightforward way to know the optimal set of components to include in your SWS file. However, you can get some hints by perusing the compile report generated when you build your application (and have the appropriate setting enabled in your Flex server configuration file). Any symbol definition marked "external" is imported from a RSL. All other symbols are linked into the application itself. Don't worry too much if a few stray classes get linked in; if you just list the MXML elements that you use, you are guaranteed to get a highly effective RSL.

About Roger Gonzalez
Roger Gonzalez is a Principal Engineer on the Flex compiler team. Prior to Macromedia, he has done everything from working on autonomous underwater robots to running the engineering group at a 3D game development studio. Roger is an avid motorcyclist, and recently relocated to California in order to pursue year-round riding.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Enterprise Open Source Magazine Latest Stories . . .
Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP). The...
With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical and st...
AMD said late Tuesday that its chief sales officer Emilio Ghilardi had left the company and that CEO and president Rory Read is going to do his job while a replacement is sought. AMD didn’t say why Ghilardi left but it’s assumed Read wants his own people. Read is relatively new to th...
During the lifespan of M3 (Monitis Monitor Manager) there has always been something lacking – timers. M3 execution procedure was outlined in this previous article. The execution mentioned in the latter was a one-time-execution, whereas server monitoring requires periodic invocati...
Red Hat is putting its bought-in Gluster scale-out NAS storage technology, acquired in October, on the Amazon cloud. It’s styled Red Hat Virtual Storage Appliance for Amazon Web Services and other clouds are supposed to follow in short order.
A new episode of the screencast series is now available at the OpenNebula YouTube Channel. This screencast demonstrates the new easily-customizable self-service portal for cloud consumers. Its aim is to offer a simplified access to shared infrastructure for non-IT end users. The scree...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE