Do more compressed PNG images take longer to load

compressionpng

When I create PNG files with very small disk size, I tend to wonder if the file size becomes less important than the time viewers would need to decompress the image. Technically that would be trivial too, but I've wondered about it for a long time. We all know that more-compressed PNG images take longer to compress, but do they take longer to decompress?

I don't know if this information affects the question, but I am wondering about this in relation to both icon-type files (which are small because they contain few pixels) and huge line-art files (which are small because they compress their pixels very effectively).

EDIT: In response to the answers I've been getting, I want to note that this is not strictly a network issue. Windows users might not notice this, but most icons used by the desktop environment are stored with PNG compression, and dozens of them need to be rendered when the system starts. The huge line-art that I referred to was mostly desktop wallpapers like the ones at http://simpledesktops.com/, but various posters, videogame resources, and other things could also fit that description.

Best Answer

Better-compressed images (i.e. with a smaller file size) should generally take less time to load than the same image with a larger size.

If you want to minimise the filesize when saving a PNG file, the sacrifice comes in the time it takes to compress the file.

The PNG compresses image data with DEFLATE (the same algorithm used in zlib and PKZIP). One way DEFLATE saves space is to encode recurring byte sequences by just providing a runlength, and an distance back to where it previously appeared in the stream. (e.g. A B C D E F A B C A B C D could be encoded as A B C D E F [3,-6] [4,-9]. (It could also encode it as A B C D E F [3,-6] [3,-3] D.)

The compressor has to use an algorithm to look for matching sequences before it can encode them. Algorithms vary, but many of them can be made to work harder or go faster using certain parameters. When an algorithm works harder, it might find more or longer matches, which usually result in better compression, but it will take longer to do it.

By contrast, the decompression algorithm is very simple and doesn't have to do much work - it just decodes the stream in a fairly linear fashion, and it doesn't have to search for matches because they are provided by the compressor - it just looks up the length/distance codes provided to it.

Generally, the fewer bits it reads in, the faster the PNG decompression is likely to be.

Related Question