An ode to bzip(purplesyringa.moe)
60 points by signa11 5 hours ago | 32 comments
- idoubtit 9 minutes agoMy experience does not match theirs when compressing text and code:
> bzip might be suboptimal as a general-purpose compression format, but it’s great for text and code. One might even say the b in bzip stands for “best”.
I've just checked again with a 1GB SQL file. `bzip2 -9` shrinks it to 83MB. `zstd -19 --long` to 52MB.
Others have compressed the Linux kernel and found that bzip2's is about 15% larger than zstd's.
- saghm 3 hours agoEarly on the article mentions that xz have zstd have gotten more popular than bzip, and my admitted naive understanding is that they're considered to have better tradeoffs in teems of collision compression time and overall space saved by compression. The performance section heavily discusses encoding performance of gzip and bzip, but unless I'm missing something, the only references to xz or zstd in that section are briefly handwaving about the decoding times probably being similar.
My impression is that this article has a lot of technical insight into how bzip compares to gzip, but it fails actually account for the real cause of the diminished popularity of bzip in favor of the non-gzip alternatives that it admits are the more popular choices in recent years.
[-]- 0cf8612b2e1e 31 minutes agoThere was an analysis which argued that zstd is pareto optimal.
https://insanity.industries/post/pareto-optimal-compression/
- fl0ki 3 hours agoThis seems as good a thread as any to mention that the gzhttp package in klauspost/compress for Go now supports zstd on both server handlers and client transports. Strangely this was added in a patch version instead of a minor version despite both expanding the API surface and changing default behavior.[-]
- klauspost 2 hours agoAbout the versioning, glad you spotted it anyway. There isn't as much use of the gzhttp package compared to the other ones, so the bar is a bit higher for that one.
Also making good progress on getting a slimmer version of zstd into the stdlib and improving the stdlib deflate.
[-]- terrelln 1 hour ago> Also making good progress on getting a slimmer version of zstd into the stdlib
Awesome! Please let me know if there is anything I can do to help
- fl0ki 1 hour agoYeah, I make it a habit to read the changelogs of every update to every direct dependency. I was anticipating this change for years, thanks for doing it!
- hexxagone 3 hours agoNotice that bzip3 has close to nothing to do with bzip2. It is a different BWT implementation with a different entropy codec, from a different author (as noted in the GitHub description "better and stronger spiritual successor to BZip2").
- pella 2 hours agoimho: the future is a specialized compressor optimized for your specific format. ( https://openzl.org/ , ... )[-]
- cgag 1 hour agoThis seems very cool. Was going to suggest submitting it, but I see there was a fairly popular thread 5 months ago for anyone interested: https://news.ycombinator.com/item?id=45492803
- srean 2 hours agoThat is an interesting link.
Does gmail use a special codec for storing emails ?
- elophanto_agent 3 hours agobzip2 is the compression algorithm equivalent of that one coworker who does incredible work but nobody ever talks about. meanwhile gzip gets all the credit because it's "good enough"[-]
- kergonath 3 hours agoBzip2 is slow. That’s the main issue. Gzip is good enough and much faster. Also, the fact that you cannot get a valid bzip2 file by cat-ing 2 compressed files is not a deal breaker, but it is annoying.[-]
- duskwuff 7 minutes agobzip2 is particularly slow because the transform it depends on (BWT2) is "intrinsically slow" - it depends on cache-unfriendly operations which can't easily be parallelized:
https://cbloomrants.blogspot.com/2021/03/faster-inverse-bwt....
- nine_k 3 hours agoGzip is woefully old. Its only redeeming value is that it's already built into some old tools. Otherwise, use zstd, which is better and faster, both at compression and decompression. There's no reason to use gzip in anything new, except for backwards compatibility with something old.[-]
- kergonath 3 hours ago> Otherwise, use zstd, which is better and faster
Yes, I do. Zstd is my preferred solution nowadays. But gzip is not going anywhere as a fallback because there is a surprisingly high number of computers without a working libzstd.
- sedatk 2 hours ago> the fact that you cannot get a valid bzip2 file by cat-ing 2 compressed files
TIL. Now that's why gzip has a file header! But, tar.gz compresses even better, that's probably why it hasn't caught on.
[-]- pocksuppet 2 hours agotar packs multiple files into one. If you concatenate two gzipped files and unzip them, you just get a concatenated file.[-]
- sedatk 2 hours agoAh okay, I thought gzip would support decompressing multiple files that way.
- saidnooneever 3 hours agothe catting issue might be more an implementation of bzip program problem than algorithm (it could expect an array of compressed files). that would only be impossible if the program cannot reason about the length of data from file header, which again is technically not something about compression algo but rather file format its carried through.
that being said, speed is important for compression so for systems like webservers etc its an easy sell ofc. very strong point (and smarter implementation in programs) for gzip
[-]- nine_k 3 hours agoBzip2 is great for files that are compressed once, get decompressed many times, and the size is important. A good example is a software release.[-]
- pocksuppet 2 hours agoSo is xz, or zstd, and the files are smaller. bzip2 disappeared from software releases when xz was widely available. gzip often remains, as the most compatible option, the FAT32 of compression algorithms.
- joecool1029 2 hours ago> the catting issue might be more an implementation of bzip program problem than algorithm (it could expect an array of compressed files). that would only be impossible if the program cannot reason about the length of data from file header, which again is technically not something about compression algo but rather file format its carried through.
Long comment to just say: ‘I have no idea about what I’m writing about’
These compression algorithms do not have anything to do with filesystem structure. Anyway the reason you can’t cat together parts of bzip2 but you can with zstd (and gzip) is because zstd does everything in frames and everything in those frames can be decompressed separately (so you can seek and decompress parts). Bzip2 doesn’t do that.
So like, another place bzip2 sucks ass is working with large archives because you need to seek the entire archive before you can decompress it and it makes situations without parity data way more likely to cause dataloss of the whole archive. Really, don’t use it unless you have a super specific use case and know the tradeoffs, for the average person it was great when we would spend the time compressing to save the time sending over dialup.
- stefan_ 2 hours agobzip and gzip are both horrible, terribly slow. Wherever I see "gz" or "bz" I immediately rip that nonsense out for zstd. There is such a thing as a right choice, and zstd is it every time.[-]
- laurencerowe 2 hours agolz4 can still be the right choice when decompression speed matters. It's almost twice as fast at decompression with similar compression ratios to zstd's fast setting.
https://github.com/facebook/zstd?tab=readme-ov-file#benchmar...
- joecool1029 3 hours agoJust use zstd unless you absolutely need to save a tiny bit more space. bzip2 and xz are extremely slow to compress.[-]
- silisili 3 hours agoI'd argue it's more workload dependent, and everything is a tradeoff.
In my own testing of compressing internal generic json blobs, I found brotli a clear winner when comparing space and time.
If I want higher compatibility and fast speeds, I'd probably just reach for gzip.
zstd is good for many use cases, too, perhaps even most...but I think just telling everyone to always use it isn't necessarily the best advice.
[-]- joecool1029 3 hours ago> If I want higher compatibility and fast speeds, I'd probably just reach for gzip.
It’s slower and compresses less than zstd. gzip should only be reached for as a compatibility option, that’s the only place it wins, it’s everywhere.
EDIT: If you must use it, use the modern implementation, https://www.zlib.net/pigz/
- hexxagone 3 hours agoIn the LZ high compression regime where LZ can compete in terms of ratio, BWT compressors are faster to compress and slower to decompress than LZ codecs. BWT compressors are also more amenable to parallelization (check bsc and kanzi for modern implementations besides bzip3).
- NooneAtAll3 51 minutes agowhy would one even care about compression speed on minecraft ComputerCraft machine?
size and decompression are the main limitations
- Grom_PE 2 hours agoPPMd (of 7-Zip) would beat BZip2 for compressing plain text data.