Avoiding linker dependencies
Mar. 28th, 2006 | 05:46 pm
While researching a problem today regarding SWF file size bloat in Flex 2.0, I learnt three different techniques to avoid unnecessary linker dependencies.
To understand the problem, let's take an example from the framework. In the source of the Application class, we used to have code like this:
// if the first child is an ApplicationControlBar,
// make it the "control bar" for the application.
if (firstChild is ApplicationControlBar)
setControlBar(firstChild);
The problem here is that the above code directly references the ApplicationControlBar type, which causes the linker to link the class into the SWF, even if it's never used in the application. Here's an unnecessary linker dependency that causes the size of many Flex 2.0 SWFs to bloat by about 1 KB. 1 KB may not seem much, but the engineers in the Flex team are rather religious about keeping the file size down to a minimum. Every byte counts.