jpgjs performance tuning

Porting https://github.com/notmasteryet/jpgjs/pull/20