I played around a bit with memory breakpoints to see when the three buffers are used. Memory breakpoints are amazing. It was while doing this that I hit the code that zeroes the 160,000,000 byte buffers. This is the call stack (from a debug build, for ease of debugging):
vcruntime140d.dll!memset_repstos() Line 35 Unknown
> blink_platform.dll!chromium_jzero_far(void * target, unsigned __int64 bytestozero) Line 133 C
blink_platform.dll!access_virt_barray(jpeg_common_struct * cinfo, jvirt_barray_control * ptr, unsigned int start_row, unsigned int num_rows, int writable) Line 968 C
blink_platform.dll!consume_data(jpeg_decompress_struct * cinfo) Line 205 C
blink_platform.dll!chromium_jpeg_consume_input(jpeg_decompress_struct * cinfo) Line 332 C
blink_platform.dll!blink::JPEGImageReader::Decode(blink::JPEGImageDecoder::DecodingMode decoding_mode) Line 654 C++
Note that Chromium uses the preprocessor to rename jzero_far and jpeg_consume, but they are otherwise unchanged.
It zeroes the memory one row at a time, so 160,000 bytes at a time in this case. As you say in the issue, changing that would be challenging, and would only help the progressive-jpeg case. The comment above the block of code in access_vert_barray says:
/* Ensure the accessed part of the array is defined; prezero if needed.
* To improve locality of access, we only prezero the part of the array
* that the caller is about to access, not the entire in-memory array.
*/
With my test image, on my machine (I'm not sure what might cause results to vary, but maybe it's timing dependent?) my memory breakpoints also showed me that the second of the three buffers is never used. My guess is that this is dependent on how many passes the progressive jpeg contains.
Aside: the more I look at this the more I dislike progressive jpegs - there are clearly many situations where they make things worse.
I do recognize that libjpeg-turbo is under resourced so I assume that if I want my issues worked on I'll probably have to do it myself, or convince Google to donate more money. I appreciate your taking the time to answer my naive questions.