alt.hn

12/26/2025 at 2:39:10 PM

Streaming compression beats framed compression

https://bou.ke/blog/compressed/

by bouk

12/30/2025 at 5:13:15 AM

Before you get too excited, keep two things in mind:

1) Using a single compression context for the whole stream means you have to keep that context active on the client and server while the connection is active. This may have a nontrivial memory cost, especially at high compression levels. (Don't set the compression window any larger than it needs to be!)

2) Using a single context also means that you can't decompress one frame without having read the whole stream that led up to that. This prevents some possible useful optimizations if you're "fanning out" messages to many recipients - if you're compressing each message individually, you can compress it once and send the same compressed message to every recipient.

by duskwuff

12/30/2025 at 5:42:38 AM

The analogy to h264 in the original post is very relevant. You can fix some of the downsides by using the equivalent of keyframes, basically. Still a longer context than a single message but able to be broken up for recovery or etc.

by adzm

12/30/2025 at 8:44:08 AM

> This may have a nontrivial memory cost, especially at high compression levels. (Don't set the compression window any larger than it needs to be!)

It sounds like these contexts should be cleared when they reach a certain memory limit, or maybe reset periodically, i.e every N messages. Is there another way to manage the memory cost?

by yellow_lead

12/30/2025 at 9:33:43 AM

LZ77 compression (a key part of gzip and zip compression) uses a 'sliding window' where the compressor can tell the decompressor 'repeat the n bytes that appeared in the output stream m bytes ago'. The most widely used implementation uses a 15 bit integer for m - so the decompressor never needs to look more than 32,768 bytes back in its output stream.

Many compression standards include memory limits, to guarantee compatibility, and the older the standard the lower that limit is likely to be. If the standards didn't dictate this stuff, DVD sellers could release a DVD that needed a 4MB decompression window, and it'd fail to play on players that only had 2MB of memory - setting a standard and following it avoids this happening.

by michaelt

12/30/2025 at 9:20:51 AM

That's a misunderstanding. Compression algorithms are typically designed with a tunable state size paramter. The issue is if you have a large transfer that might have one side crash and resume, you need to have some way to persist the state to be able to pick up where you left off.

by treyd

12/30/2025 at 5:11:08 AM

Does streaming compression work if some packets are lost or arrive in a different order? Seems like the compression context may end up different on the encoding/decoding side.. or is that handled somehow?

by lambdaloop

12/30/2025 at 5:17:30 AM

I think the underlying protocol would have to guarantee in order delivery - either via tcp (for http1, 2, or spdy), or in http3, within a single stream.

by dgoldstein0

12/30/2025 at 5:14:55 AM

It sounds as though the data is being transferred over HTTP, so packet loss/reordering is all handled by TCP.

by duskwuff

12/30/2025 at 7:33:12 AM

Yes, or by http3's in order guarantees on the individual streams (as http3 is udp)

by dgoldstein0

12/30/2025 at 5:43:33 AM

When I worked at Microsoft years ago, me and my team (a developer and a tester) built a high volume log collector.

We used a streaming compression format that was originally designed for IBM tape drives.

It was fast as hell and worked really well, and was gentle on CPU and it was easy to control memory usage.

In the early 2000s on a modest 2-proc AMD64 machine we ran out of fast Ethernet way before we felt CPU pressure.

We got hit by the SOAP mafia during Longhorn; we couldn’t convince the web services to adopt it; instead they made us enshittify our “2 bytes length, 2 bytes msgtype, structs-on-the-wire” speed demon with their XML crap.

by efitz

12/30/2025 at 9:29:30 AM

Using zstd with a tuned small file custom dictionary probably gets you most of the benefit without giving up independence of compression.

by vlovich123

12/30/2025 at 7:56:39 AM

Surely that is obvious to anyone who has compared zip and tgz?

by masklinn

12/30/2025 at 2:32:19 PM

MUD clients and servers use MCCP which is essentially keeping a zlib stream open, adding text to it, and flushing it whenever something is received. I think this has been around since 2000.

https://tintin.mudhalla.net/protocols/mccp/

by skulk