New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(gatsby-transformer-sharp): removed unnecessary conversion to webp #25325
fix(gatsby-transformer-sharp): removed unnecessary conversion to webp #25325
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EDIT: Cleaned up my reviews and discussions for future review to focus on what's important/relevant.
Note: In my own project imagemin-webp
has:
- Minimal file reduction benefits
- Results in poorer quality(blocky artifacts from compound compression vs single pass lower quality setting)
- Increased build times when processing images(50% longer).
Old review
The conditionals for `transformArgs.toFormat` seem to be more of a problem. At least for webp, that's where quality is taking a dive for minor savings. With the conditional removed, and the webp processing from sharp kept, the file is still saved to disk.This area of code is unfamiliar to me, I assume imagemin is being used as a non-optional additional compression stage, but if it's attempting to recompress an image with matching quality setting, that seems like a bad idea?
Opting out of the compression stage reduces processing by ~30% for my project, 30 seconds down to 18. The PR would probably be better to make compression opt-in/out(depending on core devs opinion), I'd personally prefer the additional compression being opt-in, unless proven that reducing quality further and extra processing time is worth what appears to be marginal gains(and potential bugs?).
…ondition to not convert to webp with `imagemin` second time in Windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not find this to be an acceptable change or fix.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Click to see investigation into why imagemin is used for each formatI've gone through the history via gatsby/packages/gatsby-sharp/index.js Lines 36 to 37 in 1f41853
That's the sole purpose we have it. In 2018, that still appeared to be the case with a lack of compression support for PNG. Looking at the changelog for sharp, we can see support for libimagequant arrived at Jan 2019, along with metadata stripping(default) and in June 2020 a further optimization for indexed palettes(auto enabled if quality/colors/dither options are set).
Thus imagemin may still be relevant for compressing PNGs. mozJPEG as an alternative encoder for providing better compression. This is supported in a manner that it only uses sharp or mozJPEG, not both. When imagemin webp was added, presumably under the assumption that since other formats used imagemin, this should too. Kyle completely overlooked it himself while reviewing the PR.. There doesn't appear to be any reason/benefit to use this plugin. The imagemin provides a variety of alternative PNG options as well as some for jpeg, the addition of imagemin-webp was likely a a mistake so it should be removed entirely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per investigation above, please remove compressWebP()
and it's imagemin-webp
dependency in it's entirety.
Optional compression for PNG can be raised in a new PR if anyone creates a new issue about it being a problem.
@polarathene Wow. Great investigation! I understand more clearer what you meant in previous comments. Thank you for that! I made new commit which deletes everything related to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for tracking this down and sending in the PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ungvert for this awesome change! I saw some size reductions and build time wins.
@polarathene awesome review! This makes my life so much easier! <3
Holy buckets, @ungvert — we just merged your PR to Gatsby! 💪💜 Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! |
Description
In process-file.js conversion to
webp
happends two times:Sharp
after.resize()
and.png()
imageminWebp
incompressWebP()
If we convert
png
image with transparency towebp
and then we pass thiswebp
image toimageminWebp
- it returns image with weird artefacts and black background (tested on Windows 10).I don't comprehend why we doing the conversion two times. Parameters of conversion seems identical.
Related Issues
Fixes #14497