Page MenuHomePhabricator

Use Chroma subsampling for image thumbnails (save 17% bandwidth and save memory on mobile)
Closed, ResolvedPublic

Description

http://calendar.perfplanet.com/2015/why-arent-your-images-using-chroma-subsampling/

Looking at today's featured picture at https://en.wikipedia.org/ it seems we don't have this enabled for our thumbnails.

https://upload.wikimedia.org/wikipedia/commons/thumb/1/13/Poecile_montanus_kleinschmidti.jpg/760px-Poecile_montanus_kleinschmidti.jpg

$ identify -format "%[jpeg:sampling-factor]" Poecile_montanus_kleinschmidti.jpg 
1x1,1x1,1x1

Which suggests 4:4:4 as opposed to 4:2:0. The difference is should be minimal visually (especially for thumbnails), and not only saves bandwidth costs and download time, but also processing memory (useful for mobile) - this contrary to some other compression features.

Event Timeline

Krinkle raised the priority of this task from to Needs Triage.
Krinkle updated the task description. (Show Details)
Krinkle subscribed.
Restricted Application added subscribers: StudiesWorld, Steinsplitter, Aklapper. · View Herald Transcript
MarkTraceur subscribed.

@MarkTraceur, is this something your team could take on? The impact would be substantial.

For the record, this is a suggested improvement for all our thumbnails across the board. Not mobile-specific, or otherwise optional.

@MarkTraceur, ping -- is this something your team could take on?

Sorry about that.

At a glance, it might be something we could work on, but I'd want pretty broad buy-in from people who upload images, especially diagrams with high detail, before we took it on. I don't want to end up with ugly-looking graphs and diagrams in articles because we change the thumbnailing software.

Not really, we're Editing/Multimedia, with stress on the Editing. Someone might overrule me, but this doesn't look like something that matches the team's purpose, and it doesn't look like something that anyone on the team has experience with.

@matmarex is correct about that, also, though I wouldn't rule it out entirely, and it's not my call.

@Krinkle and I spoke about this on IRC, and I'm convinced, particularly because:

I suggest telling COM:VP and VPT about this, at least once, maybe twice. Wikitech ambassadors would probably appreciate a notice, too. I don't think we need consensus, given the performance gain it would give us compared to the tiny hit we'd take in detail.

I coulda sworn the default on JPEGs was 4:2:0 but I've spent a lot more time working on video than with JPEG setting tweaks. :D Offhand using 4:2:0 chroma subsampling is a very good idea for nearly all photo-based thumbnails, and if we're defaulting to 4:4:4 we should definitely switch. Will look over details and comment more later.

It's probably a very simple fix when using ImageMagick thumbnailing; what's the state of the art on upcoming new stuff (thumbor?)

In T122242#2077909, @brion wrote:

It's probably a very simple fix when using ImageMagick thumbnailing; what's the state of the art on upcoming new stuff (thumbor?)

@Gilles' Thumbor stack for MediaWiki still uses ImageMagick behind the scenes, so it's most likely one fix that needs to be applied in two places.

Three: JPEG media handler in core, VIPS (which we use for large JPGs), Thumbor.

VIPS doesn't seem to offer a way to set a specific chroma subsampling value. It only has an option to "disable" chroma subsampling.

As for IM, it seems like by default it's letting the JPEG library do its thing. Which seems to be either 4:4:4 or keeping the same as the original in production.

And for syntax, both of these seem to work and produce the same result:

convert -sampling-factor 4:2:0
convert -sampling-factor 2x2

I'll add that as a configuration option to Thumbor, for engines that can handle it: T129073

@brion, could you take on the task of modifying the JPEG media handler in core?

@ori can do (core JPEG handler update); do we want to assign this whole task to me or break up to subtasks so we don't forget the other bits?

@Krinkle thanks! T129128 is now assigned to me and on my short list for next couple weeks.

convert -define jpeg:sampling-factor=4:2:0

also works

Change 285669 had a related patch set uploaded (by Brion VIBBER):
[WIP] Enable 4:2:0 chroma subsampling for JPEG thumbnails

https://gerrit.wikimedia.org/r/285669

Removing patch tag as that patch belongs on subtask T129128.

Jdforrester-WMF claimed this task.
Jdforrester-WMF subscribed.

Turns out we don't use VIPS for JPEG thumbs in WMF production, so I removed that blocker.

Consequently, this has been done since 1.27.0-wmf.23.

Ah, so JPEGs *of* TIFFs, not JPEGs of JPEGs.

Ok, so that one also shows as 4:2:0:

jpeg:sampling-factor: 2x2,1x1,1x1

Hmm, PagedTiffHandler appears to be hardcoded to use ImageMagick:

https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FPagedTiffHandler/master/PagedTiffHandler_body.php#L318