4 min read
Compress and decompress with lzma vs bz2, with zlib as a familiar reference (lab 102 covers zlib vs gzip). This lab reports MB/s and size ratios on Linux localhost.
Related links:
Lab honesty (1 Oct 2026 IST): Python 3.13.5. Affiliates: 0. Payload: 1048536 bytes of a repeated log line (highly compressible — ratios look extreme on purpose).
Verdict up front: compress — lzma ~62.48 MB/s (out 356 B); bz2 ~4.53 MB/s (out 550 B); zlib ref ~320.27 MB/s. Decompress: lzma ~1708.96, bz2 ~144.08.
| Arm | Pattern |
|---|---|
lzma.compress/decompress | XZ/LZMA2 defaults |
bz2.compress/decompress | bzip2 defaults |
zlib.compress(...,6) | reference only |
Seven rounds, p50. Round-trips OK (lzma=True, bz2=True).
Script: lab-evidence/143-lzma-vs-bz2/results/run_lab.py.
| Arm | MB/s | out/in bytes | ratio |
|---|---|---|---|
| lzma compress | 62.48 | 356 | 0.0003 |
| bz2 compress | 4.53 | 550 | 0.0005 |
| zlib compress (ref) | 320.27 | 3656 | 0.0035 |
| lzma decompress | 1708.96 | 356 | — |
| bz2 decompress | 144.08 | 550 | — |
| zlib decompress (ref) | 1935.2 | 3656 | — |
The fixture repeats one log line to ~1 MiB. That is a realistic “agent dumps the same template” case, not a claim about JPEG. lzma’s 356-byte blob vs bz2’s 550 still shows lzma packing tighter on this pattern while compressing faster.
lzma decompress hit ~1708.96 MB/s vs bz2 ~144.08. Read-heavy pipelines that already store .xz stay fine; do not pick bz2 hoping decode will save you if encode was the bottleneck.
Put codec choice in the runbook next to retention: “xz for cold archive, gzip for hot ship.”
zlib’s ~320.27 MB/s compress on this fixture is the speed ceiling among the three, with a larger 3656-byte blob. That matches the usual trade: gzip/zlib for hot ship, lzma for cold archive. Lab 102 remains the zlib-vs-gzip deep dive; this post only borrows zlib as a yardstick while crowning lzma over bz2 in the stdlib heavy tier.
On less repetitive data, absolute MB/s and ratios will move — rerun the script on a production sample before changing default codecs in an agent.
Evidence: summary.json, summary.txt.
One Linux box, default presets, one synthetic repetitive corpus. Not zstd (lab 33).
On this repetitive ~1 MiB log fixture, lzma compressed at ~62.48 MB/s to 356 bytes vs bz2 ~4.53 MB/s / 550 bytes. Prefer lzma over bz2 in stdlib; keep zlib/gzip for hotter paths.
Lab evidence
Ran the included lzma-versus-bz2 compression benchmark on Linux localhost with Python 3.13.5. Seven rounds used a 1,048,536-byte repeated log-line payload, measuring p50 compress and decompress throughput plus output-size ratios. lzma compressed faster and smaller than bz2 on this corpus, while zlib was the speed reference. Both codecs round-tripped successfully; random or already-compressed data could differ.
Summary1 Oct 20263 min read
Summary1 Oct 20263 min read
Hands-on gc.collect cost empty vs cyclic garbage lab: real collect latency plus reclaim counts, measured on Linux localhost today in this lab for SREs.
Hands-on1 Oct 20264 min read