While RSLs help to reduce the size for your Flex applications, they can sometimes be tricky to use. So to simplify the usage of RSLs, we made some enhancements in the upcoming Flex SDK release (code-named Hero).
These enhancements should provide the following benefits:
- Applications will only load RSLs that are required
- Modules (and sub applications) will use RSLs which are already loaded by the parent application (or module)
- Enable sharing of RSLs between modules (and sub applications)
- Simply usage of Monkey Patch with Flex RSLs
Only load what’s needed
In Flex 4, all RSLs that were listed in the flex-config.xml (at compile time) were loaded by the app when it was launched. But with the Hero release the compiler will remove any RSLs which are not needed by your application. This means that the load time for your app should improve because it won’t load any extra RSL. The RSLs removed by the compiler will be the placeholder RSLs. This feature is controlled by a new compiler switch called -remove-unused-rsls which defaults to true.
Also if you compile your app using the command line compiler, then it will print the names of the RSLs that are needed by your application. The following is an example of compiler output where the app uses 3 out of the 10 RSLs listed in flex-config.xml

There could be cases where the compiler may remove RSL which is needed by your app (say if you used soft-linking to load classes from a swc). If you run into such a situation then you can override the compiler’s decision, to remove the RSL, by using the -force-rsls compiler switch. This option takes the path of the swcs for which the RSLs should be force loaded.
Use what’s already loaded
Starting with Hero, modules and sub-applications will use the RSLs loaded by the parent app instead of loading a duplicate copy.
When a module or sub-application loads a new RSL, the RSL will be loaded into the default application domain and if this was the placeholder RSL for the parent app then it will be loaded into the parent’s application domain. Now if the parent app loads another module or sub-app which needs the same RSL then it will be able to use the RSL loaded by previous module or sub app.
The image below is an example of application where the OSMF RSL is removed by the compiler and so it becomes the placeholder RSL for the main app.

In the following image, the main app loads a module that uses spark video player. The module needs OSMF RSL so it loads it into the app domain of the parent application because OSMF RSL is a placeholder RSL. The module does not load the Framework or Spark RSLs because those were already loaded by the parent app.

Now if the main app loads another sub app which needs OSMF RSL, then the sub-app will simply be able to use the OSMF RSL loaded by the module.
You can also specify the application domain where the module should load the RSL. The -application-domain compiler option takes the path of the swc and then the name of the application domain. The valid values for application domain are ‘current’, ‘default’, ‘parent’, or ‘top-level’
Smaller Framework RSL
In Hero, we also reduced the size of the framework RSL. This was done by removing all mx components from framework.swc and moving them to a separate swc called mx.swc. So if you are creating pure spark apps then you don’t need to load any mx classes.
Monkey Patch RSL
The only way to use monkey patches with Flex RSLs is to load monkey patched file as RSL itself. But again it was quite tedious to create a monkey patched RSL, so to simplify that a new compiler option (called -include-inheritance-dependencies-only) was added. This option can be used when compiling the monkey patched library. This options works with -include-classes flag and it only pulls dependencies which are of type inheritance. An example for usage of this option:
bin/compc -include-classes=spark.components.Button -sp=frameworks/projects/spark/src/ -include-inheritance-dependencies-only=true -output=patch.swc
In the above example, the output swc will contain spark.components.Button and only it’s inheritance dependencies. And the library.swf contained in the output swc can be used as an RSL if you were to monkey patch the spark button component.
Most of these changes (except for the -application-domain compiler option) are already available in the latest Hero preview build.
Great job!
When are you going to release Hero?
No formal date has yet been announced but it will be in 2011. That’s all I can say at this point..