Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
While updating Zola from 14.1 to 16.1 (congratulations and great work!) I noticed that image resizing slowed down significantly.
On my website I don't track my
static/processed_images
in the main branch, instead I keep a working copy on mygh-pages
branch which is published. So, when I was bringing up a new machine I pulled the latest Zola (16.1) and started the initial build process which would process the images.To my surprise, after nearly 20 minutes on a 32 core machine, it wasn't done resizing around 465 images. Usually this process only takes a couple minutes.
I noticed I could open an image during the build process and watch as it was saved. It seemed to be saving pixel by pixel, which would indeed be much slower than a buffered writer as my proposed solution suggests.
Resolution
Here we use the
image::DynamicImage
type which has thewrite_to
function:zola/components/imageproc/src/lib.rs
Lines 325 to 343 in ad6c834
According to the
write_to
docs, it assumes a buffered writer, so we should provide one.How it happened
In Zola 0.14.1 we depended on image 0.23:
zola/components/imageproc/Cargo.toml
Line 11 in 3dcc080
This version of image does not include the
BufWriter
notice onwrite_to
.In Zola 16.1, we depend on image 0.24:
zola/components/libs/Cargo.toml
Line 17 in 195b6bd
This version includes the warning on
write_to
.Performance
Prior to these changes, building took over 26 minutes (I got bored and cancelled):
With these changes it only took 20 seconds:
Sanity check
Code changes
(Delete or ignore this section for documentation changes)
next
branch?If the change is a new feature or adding to/changing an existing one: