How my stupid package name made my users updates 5 times too big...

by Samuel Attard

So this is an interesting one, I bet you're all sitting there trying to figure out how something as abstract as a package name has any affect on the size of update files.

Yeah... That's what I spent hours puzzling over as well :D

In The Beginning

So for the last couple of updates to GPMDP I've been noticing the delta update files have been getting bigger and bigger regardless of the code change. One update I changed a single line of code and the delta file was 12MB.

This of course bugged me quite a lot but I didn't have time to track down the problem and let's be real. It wasn't a critical issue.

What Changed

As of GPMDP 3.6.0, the build system would not build a delta package. It successfully built the installer and the RELEASES file but failed miserably to provide the small, quick to download delta package that I wanted.

Tracking it Down

So after a quick conversation on Slack with @paulcbetts I realized that Squirrel.Windows couldn't find a previously released version to generate a delta against. This was strange as it was finding 3.4.0, 3.5.0 and a few versions in between but was thoroughly convinced that none of them preceded 3.6.0.

After lots of debugging and manual builds of Squirrel.Windows I found the offending code block.

static readonly Regex _versionRegex = new Regex(@"\d+(\.\d+){0,3}(-[a-z][0-9a-z-]*)?$", RegexOptions.Compiled);  

This is the regular expression that Squirrel.Windows uses to extract the version number of the package from the package name. For instance:
Atom.1.10.4-full.nupkg --> Would extract the 1.10.4.

Here's the kicker though, my package ID is GPMDP_3, this results in file names such as GPMDP_3.3.6.0-full.nupkg. The regular expression extracts 3.3.6 as the version number from this filename.

As you can imagine this causes a whole bunch of issues with delta generation as it attempts to find a version before 3.3.6 to delta against when it should be looking for 3.6.0. One regular expression = hours of debugging.

This means that for version 3.5.0 it thought it should generate the delta for 3.3.5 which means it was generating it against 3.3.4. This caused an ever increasing delta size as it was always calculating the delta from 3.3.4.

Fixing it

The fix for me at any rate was to use a slightly modified regular expression.

static readonly Regex _versionRegex = new Regex(@"[\-\.]\d+(\.\d+){0,3}(-[a-z][0-9a-z-]*)?$", RegexOptions.Compiled);  

This simply checks for a . or a - before the version number so we know that it correct.


Well, we've all learned a very valuable lesson today

1. Don't use stupid package names
2. Regular expressions are tricky buggers :)