wildlyinaccurate / jekyll-responsive-image

An unopinionated Jekyll plugin for generating and using responsive images
MIT License
332 stars 48 forks source link

Improving build performance when a lot of images have already been resized before #100

Closed danielpietzsch closed 3 years ago

danielpietzsch commented 4 years ago

Hi @wildlyinaccurate,

This is my suggestion for improving the performance of a Jekyll site build when a lot of the site’s (resized) images have previously already been generated.

My site takes a lot of time to re-build, although no new images are being generated for the vast majority of those rebuilds: I currently have around 2900 images. And for each of those, 3 additional sizes are generated. A rebuild of that site without any new image-resize operations takes more than 140 seconds. With this modification, it only takes around 14 seconds.

The main thing I did for this was to open the original image using .ping instead of .read. .ping omits the pixel data for the image resulting in a faster read and less memory usage. The full image – including pixel data – is only loaded, when resized versions actually need to be created.

The tests pass.

Hope you like it! :-)

Update: Btw, I also did test full rebuilds of my site, generating resized versions of all 2900 images, to make sure it does not worsen that use-case. And the generation time remained between 14 and 15 minutes – as it did before with the master branch.

All the times listed are for my 2018 MBP 13” 2,3 Ghz Quad-Core i5.

coveralls commented 4 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 82e868966c18c170d96199c78657c5092cf4a54d on danielpietzsch:improveRegeneratePerformance into fa00c4c9cfcea157e535c50a9361b839b6814649 on wildlyinaccurate:master.

wildlyinaccurate commented 4 years ago

Hey, thanks so much for submitting this! I have a busy week coming up but I'll try to make some time to properly review and test this before merging it.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

wildlyinaccurate commented 3 years ago

Bad bot! So sorry I haven't got around to this yet 😱

danielpietzsch commented 3 years ago

No worries. I’m not in a rush.

brandonb927 commented 3 years ago

Just throwing my hat in the ring here to have this PR considered, I have several hundred images on my site and it takes forever to rebuild making simple changes while dev'ing. I'll see if I can pull this down soon and test it as well!

wildlyinaccurate commented 3 years ago

Sweet thanks @brandonb927! I FINALLY got around to testing this on my sites, and I can't see any issues with it. @danielpietzsch this is a pretty sweet change btw - my biggest site only has 75 images but the build time dropped from 3.0 s to 2.5 s. I'm amazed it made that much of a difference!

wildlyinaccurate commented 3 years ago

I'll merge this PR to master now but hold off on releasing a new version for a little bit. @brandonb927 if you do end up testing this (and please don't feel obliged to!) I'd be keen to hear what kind of improvement it made to your build :)

danielpietzsch commented 3 years ago

@wildlyinaccurate Thanks for testing and merging! 😃

brandonb927 commented 3 years ago

I can confirm that there is probably ~15% increase in speed when generating images from this 🎉 Thanks @danielpietzsch!