All about mobility

I went to the local .NET users group here in Canberra (after missing a few too many meetings at my local group) and saw a presentation on mobile development from Smart Client Program Manager Jonathan Wells. Jonathan looked like he was in the twilight-zone, and said that he had given the talk in 8 different cities since Monday (yikes), but his talk was surprisingly lucid. I’ve been keen to write something for my SmartPhone, and have just started working on a Compact Framework project so I’m certainly interested in the topic.

One thing that came up was obfuscation of source code to reduce the code size (for deployment to devices). I had heard Jeffrey Richter mention this on DotNetRocks once, and wanted to know if Jonathan had any thoughts on if this was a good idea or not. He gave the classic performance question smackdown - “measure it and see for yourself”, so I did. In my pseudo-scientific test I randomly chose the following assemblies from the CF and obfuscated them with the community edition of Dotfuscator that comes with VS.NET 2003 (Note: Dotfuscator Professional which I did not use bosts “Comprehensive support for the .NET Compact Framework“ whatever that means). Here are the size differences between the “regular” assemblies and the obfuscated ones.

Assembly Size (before obfuscation) Size (obfuscated) Difference
Microsoft.VisualBasic.dll 136 128 6%
System.Data.Sqlclient.dll 145 128 12%
System.Data.SqlServerCe.dll 121 109 10%
System.Drawing.dll 38 31 18%
System.Net.IrDA.dll 11 10 9%
System.SR.dll 91 92 (1%)
System.Web.Services.dll 94 83 12%
System.Windows.Forms.dll 137 116 15%
System.Xml.dll 197 173 12%

Dotfuscator also has a “library” mode where exposed APIs are not obfuscated. Here is the size difference using this library setting for the same random sample:

Assembly Size (before obfuscation) Size (obfuscated) Difference
Microsoft.VisualBasic.dll 136 132 3%
System.Data.Sqlclient.dll 145 133 8%
System.Data.SqlServerCe.dll 121 115 5%
System.Drawing.dll 38 39 (3%)
System.Net.IrDA.dll 11 11 0%
System.SR.dll 91 92 (1%)
System.Web.Services.dll 94 89 5%
System.Windows.Forms.dll 137 134 2%
System.Xml.dll 197 185 6%

Note that in a couple of cases the size of the assembly actually increased, which seems very odd. Assuming that this random sample is representative of the size savings that could be achieved across the whole Compact Framework (roughly 4 -5%), think of the missing functionality that could have been added in the 100~ish K extra space they would have had. That’s about the size of System.Web.Services.dll in the Compact Framework. Like so many other things, some of this missing functionality is fixed in whidbey. Apart from the Compact Framework team (who apparently had a very strict size requirement and tons of functionality to try and cram in) I don’t know if obfuscation for size reduction makes a great deal of sense given that the gains are not that great. Also I don’t know how obfuscation like this affects run-time performance.

As well as a good presentation from Jonathan I got a DVD with all the presentations from the Mobile DevCon from this year, and a bunch of other freebies. Love those freebies.