WordPress / performance

Performance plugin from the WordPress Performance Group, which is a collection of standalone performance modules.
https://wordpress.org/plugins/performance-lab/
GNU General Public License v2.0
364 stars 99 forks source link

Explore/research MozJPEG #294

Open adamsilverstein opened 2 years ago

adamsilverstein commented 2 years ago

Feature Description

Contributors have pointed out that MozJPEG compression provides benefits over traditional JPEG compression without the potential compatibility issues WebP present.

The goal of this issue is to research MozJPEG further to evaluate its benefits and see how it can be used in WordPress.

Here are some initial questions to consider:

henrihelvetica commented 2 years ago

MozJPEG, as in the encoder?? The only research I'm aware of are the ones that were associated w/ the original release announcement in 2014.

Dated, but maybe it helps.

erikyo commented 2 years ago

This is what I found on this topic:

What do hosts need to do to make MozJPEG available on the server? (complex)

Since MOZjpeg is a fork of the default encoder (jpeg-turbo) hosts need to build and install the encoder replacing the default one.

Is it (or can we make it) available by default in PHP GD?

Yes but we need to recompile PHP with MozJPEG instead of libjpeg

Is MozJPEG compression detectable from image meta (if not stripped)?

No, afaik isn't possible

How does it compare to WebP? - final file size at same dssim from original - level of effort (===energy) to compress/decompress.

Mozjpeg weighs 10% more than Webp at the same SSIM (source) and does not support alpha channel. However, it can be advantageous if the original is an already over-compressed jpg, it seems to degrade the original image less than the competitors, maybe because the same codec

Can/should we detect support in PHP and show a message in site health regarding support?

No, afaik isn't possible

More generally it would be great to answer - how widespread is support for MozJPEG for WordPress? How many sites can already leverage MozJPEG?

I think it's a very specific setup that few people currently have with php (whereas it is much easier with nodejs). I installed it but it is not currently working with Wordpress, I should replace cjpeg (system wide) but don't know if it's worth it, at least for the moment.

bgoewert commented 2 years ago

Stumbled upon this issue after reading Is WebP Really Better Than JPEG? by @joppuyo, which compares JPEG, MozJPEG, WebP, and AVIF using the Kodak image dataset at different image sizes (500x, 100px, 1500px).

So, is WebP better than JPEG? It depends if you are using the reference libjpeg library or the improved MozJPEG encoder.

WebP seems to have about 10% better compression compared to libjpeg in most cases, except with 1500px images where the compression is about equal.

However, when compared to MozJPEG, WebP only performs better with small 500px images. With other image sizes the compression is equal or worse.

I think MozJPEG is the clear winner here with consistently about 10% better compression than libjpeg.

But as with most things, there were caveats with this test.

I only used photographic images.

I also tested the images in “Web quality” target of 85 so WebP may perform differently in very high or very low-quality settings.

Also, Google’s study used a different program to compute the SSIM values. In my tests, I used the dssim utility which computes multi-scale SSIM in LAB color space while the former seems to use simple SSIM in RGB color space.

adamsilverstein commented 1 year ago

Yes but we need to recompile PHP https://github.com/mozilla/mozjpeg/issues/345 instead of libjpeg

I wonder why this isn't enabled by default when available?

joppuyo commented 1 year ago

Yes but we need to recompile PHP mozilla/mozjpeg#345 instead of libjpeg

I wonder why this isn't enabled by default when available?

Because libjpeg is the default JPEG library in most Linux distributions and other operating systems. If you wanna use MozJPEG, you will need to explicitly install it and recompile ImageMagick/GD using MozJPEG.

This is really an issue with the server environment and not the application code so WordPress can’t really influence what’s going on under the hood. It will simply use whatever JPEG library the server administrator has installed.

adamsilverstein commented 5 months ago

Noting here that we should be able to achieve MozJPEG compression using client side image processing, maybe something to explore as part of that work.