Gzip against brotli on an API response, measured

Brotli compresses better and costs more CPU, and whether that is worth it depends on a number nobody measures.

a 240 KB JSON response, on our hardware:

  none            240 KB    0.0ms
  gzip -6          28 KB    2.1ms
  gzip -9          27 KB    8.4ms
  brotli -4        24 KB    2.8ms
  brotli -11       19 KB   142ms

chosen: brotli -4, gzip -6 as the fallback.
rejected: anything above -5, which trades 5 KB for
100ms of CPU on every response.

The high compression levels are for static assets compressed once at build time, and using them for a dynamic response is the mistake this table exists to prevent. For a 240 KB payload the difference between the sensible settings is 4 KB, which on a mobile connection is about 40 ms — genuinely worth the 0.7 ms.