On how I accidentally may have made a feature 75% faster.
UPDATE: After fixing bugs, it turns out the improvement is roughly 25%, not 75%, which is still nice :-)
Image galleries is one of my favourite features in Nikola
I use them in my site and they are awesome! Just dump a bunch of images in a folder and you will have them nicely presented. Then you can add a file with a folder description amd so on.
One thing I did not like was that they were pretty slow. My site has 3290 images in the galleries section, and I dreaded processing them because they took forever, where forever means around 5 minutes.
Unrelated to performance, we had a feature request for supporting multiple thumbnail sizes, which is useful for things like presenting the ideal image size for your display and such.
Well, to support that someday, a good first step is to have our generic image processor class support more than one thumbnail size. So, just take the scale_image
implementation and have it support more than one size and more than
one destination path, then loop over those, and that's that. Right?
OTOH, it turns out we processed each image TWICE because we would clean EXIF data and/or resize the "original" images. Sometimes the source images have resolutions that simply make no sense on a website!
So, since our implementation of scale_image
only accepted one destination, we would:
- read original image -> cleanup -> resize to thumb size -> save
- read original image -> cleanup -> resize to "large" size -> save
So, since I had now a version that could do the "resize" and "save" parts on one call, this became:
- read original image -> cleanup
- resize to thumb size -> save
- resize to "large" size -> save
And the really slow part is ... reading the original image. So this suddenly made the whole process take 25% of the time it took before.
In my specific site, it went down from 356 seconds to 112 seconds. That's a 70% decrease in rendering time. Which is big. And in code I first wrote around 2013, that is huge.
So, the lesson is ... I am a crappy programmer, maybe? Or used to be? Or maybe just that even old, mature code could still have large opportunities for improvement?
Who knows.