Bug 1054803 - improve size-matching algorithm, r=aosmond