BlogsCloudflareImage Optimization Performance

Image Optimization Performance

Image Optimization Performance

4
posts
2012–2015

Cloudflare's image optimization capabilities have seen significant performance improvements through the application of SIMD instructions, particularly AVX2, to computationally expensive image processing tasks like JPEG compression. This evolution focuses on optimizing parsers and image processing algorithms to enhance website performance and reduce server load. The Polish product has been updated to use mozjpeg 2.0, which offers better compression ratios and a higher success rate in compressing images. This post introduces Polish, which automatically optimizes images by removing unnecessary bloat and applying compression (lossless or lossy) to reduce file sizes, leading to performance gains, especially for mobile devices.

2015

Doubling the speed of jpegtran with SIMD

10/8/2015

This post details the optimization of the jpegtran tool for JPEG image compression by leveraging SIMD (Single Instruction Multiple Data) instructions. The author profiles jpegtran, identifies Huffman coding functions as performance bottlenecks, and applies SIMD intrinsics to accelerate loops for absolute value calculation, right shifting, and zero-value skipping. These optimizations resulted in a 2.25x speedup for the tested image.

2014

Improving PicoHTTPParser further with AVX2

12/18/2014

This post details the optimization of PicoHTTPParser using AVX2 instructions, moving from SSE4.2's PCMPESTRI. The optimization involves a shift from latency-bound to throughput-oriented logic by creating bitmaps of all token occurrences within a larger chunk of data (128 bytes) and combining masks for different token types. This approach, when compiled with gcc 4.9.2 and specific flags, resulted in a 1.68x to 1.79x performance improvement on Haswell processors.

Experimenting with mozjpeg 2.0

7/29/2014

This post details the evaluation and adoption of mozjpeg 2.0 for Cloudflare's Polish product. It compares mozjpeg 2.0's compression performance and CPU usage against libjpeg-turbo using a sample of 10,000 JPEG images. The findings indicate that mozjpeg 2.0 achieves better compression ratios (3.0% vs 2.5% on average) and successfully compresses a higher percentage of images (93.1% vs 65.3%). However, it also incurs a higher CPU cost (1.7x longer runtime). Cloudflare plans to further optimize mozjpeg 2.0 for Intel processors and contribute improvements back to the project.

2012

Introducing Polish: Automatic Image Optimization

6/5/2012

Introduced Polish, an automatic image optimization feature. Polish offers two modes: Lossless (removes bloat like metadata, ~21% reduction) and Lossy (removes bloat and applies compression, ~48% reduction). The feature is available for paid accounts and operates by optimizing images in the cache.