Saturday, January 22, 2011

The Silverlight SDK and XAP File Sizes

Microsoft shipped a variety of useful controls with Silverlight.  Some are built into the runtime, while others are in the SDK.  While the use of runtime controls has no substantial penalty in your XAP file size, if you want to use any controls from the SDK you have to include the System.Windows.Controls assembly or one of its sub-assemblies.

As of today, this is the final (XAP compressed) overhead that you can expect from each assembly:

90 KB   - System.Windows.Controls
216 KB - System.Windows.Controls.Data
48 KB   - System.Windows.Controls.Data.Input
121 KB - System.Windows.Controls.Input
28 KB   - System.Windows.Controls.Navigation

In 2009 when I was developing Regex Hero I was determined to keep it very lightweight.  Most of the controls I was using were from the Silverlight runtime.  In fact the only one that I was using from the SDK was the GridSplitter.  But I wanted to know how I could include the GridSplitter in my project without including the full System.Windows.Controls.dll from the SDK.  Turns out that Microsoft released the source code for the SDK and runtime controls from Silverlight 2.  Long story short, I was able save 60 KB from Regex Hero by stripping the GridSplitter out into its own control and using it instead.  After that, Regex Hero was only 51 KB.

In total, I've stripped out these 4 controls from System.Windows.Controls:

Just as I did, you can download any of the controls above to eliminate your need for the System.Windows.Controls assembly and reduce your XAP file size.  However, as a rule I'd say that if you need more than 2 of these controls, simply use the System.Windows.Controls assembly instead.  There will be some overlap in these controls and after a certain point it makes more sense to simply use the original assembly.

There are a lot more controls in the various other assemblies but not all of the source code is available from Microsoft.  Maybe some day they will release the up-to-date code for the rest of the SDK and I can apply the same treatment to them.

No comments:

Post a Comment