Reducing Filesizes Using Abstraction
I had recently came across a situation with a project of mine where concrete referencing resulted in a SWF file that was far more bloated than it clearly should have been. Yet another reason why abstraction is so great — although perhaps it should have been obvious in the first place.
The project in question revolves around an MVC architecture, where multiple distinct view/controller pairs share a common model. The pairs were completely independent from each other with the exception of said model, and each were relatively expensive to instantiate. Because of this, I decided to compile each pair into separate module SWFs that would be loaded into a single wrapper SWF. In addition to loading, the wrapper would also create the model and pass it into all of the modules.
I soon realized the wrapper SWF had become 160KB in size…
Clearly, something was wrong, so I investigated.
As it turned out, I had been referencing the loaded modules by their document classes. I wasn’t really concerned about abstraction, since I had a very specific implementation in mind for the wrapper. However, the wrapper was compiling not only the concrete classes, but all of the concrete references made by those concrete classes. This can increase exponentially when some of those concrete references also happen to be embedded assets.
Since all the module SWFs used a single method call to both retrieve the model and initialize themselves, I decided to set up a quick interface, recompile the modules, and then reference the modules via the interface within the wrapper. Sure enough, the payload for the wrapper dropped from 160KB to a much healthier 4KB.
Just one of those things that makes sense in retrospect, but is only ever realized once you fall into the situation.

