You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that in my experience, zstd and brotli don't compress binaries better than xz.
Nix does already support brotli compression (e.g. nix copy --to file:///bla?compression=br). Unfortunately, the default compression quality (11) makes it superslow, about 10x slower than xz -6 (with a worse compression ratio). OTOH with quality 6 it's 6x faster than xz -6. So we really should have a setting in Nix for the compression quality.
@edolstra That's correct, xz remains to have the best compression ratio (this is also stated in the article I linked). The idea is that it compresses a lot faster.
So we really should have a setting in Nix for the compression quality.
@edolstra That would be very appreciated; while zstd seems to do even better than brotli, being able to use brotli at level 4 would already be a huge improvement (4x vs gzip, 60x vs xz).
We already have an option for enabling multithreaded compression, options for compression level seem like an easy addition (I say this to indicate that anyone interested can tackle this).
Hardest part seems to be sorting out how this should be specified in context of each compression method having different ranges and defaults. But I think they all support a basic notion of integer level so this seems workable...
As for zstd, implementing support for it is likely also rather straightforward -- I haven't seen it's API but AFAIK they are all loosely similar. I was able to add brotli support pretty easily, for example, and I'd never used it's API before.
I can't promise support for every compression technique will be eagerly merged but zstd seems reasonable addition...
In short: these features likely take only an hour or two of an interested party's dev time, so if you want this supported consider tackling it and submitting a PR! The relevant parts of Nix involved here are rather accessible and don't rely on much beyond the task at hand (and maybe source/sink abstractions).
How did they achieve only 0.8% package size increase? Impressive ratio for zstd. Maybe xz compressed package size was a factor of 0.8 compared to zstd and not percentage?
Max compression level? Looking and the zstd manual, it's not promising, affecting decompression:
--ultra
unlocks high compression levels 20+ (maximum 22), using a lot more memory. Note that decompression will also require more memory when using these levels.
The request is interesting. But the current points for xz (lzma) are saved network bandwidth and server storage costs.
If it happens that download speed is slower than decompression while both are done in a streaming fashion (currently not), then we (users) hardly win anything.
15 MiB/s is 120 Mibit/s. I wonder if many of us do really have this download speed from cache.nixos.org. So the request is more oriented towards uploading caches to private servers.
As for common users I don't know if it is tricky to implement download->decompression streaming for nix store (most notably hash validation should happen after? (but xz -d checks integrity too)). But this brings to a question what are we going to solve and by which means?
I think the real benefit is on the compression side
Seconding this. nix copy for large outputs generally spends a ton of time just compressing and failing to saturate the uplink. Parallel compression helps (and also comes at a cost of compression ratio), but is still insufficient to saturate the uplink in certain setups.
You can use a dictionary with brotli, too. Even if you train it with zstd dictionary search.
If you make the window size the same as in zstd, and the LZ77 search is done exactly the same way, brotli will be the same speed, but ~5 % more efficient due to the context modeling (depends on your data). From purely theoretical point of view, brotli format is better-suited for high compression speed and zstd better suited for fast decompression. Brotli also has slightly better streaming properties -- not hiding as much data as zstd from the data you already received as the data is multiplexed ideally for streaming in brotli and for decoding speed in zstd.
You can control brotli's window size with --window 24 or --large_window 30.
Oi. Brotli was made only as a data stream, not to a file format (think deflate stream vs gzip). We need to place it into a container like shared brotli.
Activity
nh2 commentedon Jun 28, 2018
Moving discussion from cachix/cachix#55 (comment) over here:
@edolstra That's correct,
xzremains to have the best compression ratio (this is also stated in the article I linked). The idea is that it compresses a lot faster.Here are some examples:
zstdisgzipwhile having the same output sizexzwhile having 30% increased output sizebrotli --quality=4while having the same output sizeIt also supports mutliple cores; when used, that bumps the above numbers by some more integer factors:
nh2 commentedon Jun 28, 2018
@edolstra That would be very appreciated; while
zstdseems to do even better thanbrotli, being able to usebrotliat level 4 would already be a huge improvement (4x vsgzip, 60x vsxz).dtzWill commentedon Jul 4, 2018
We already have an option for enabling multithreaded compression, options for compression level seem like an easy addition (I say this to indicate that anyone interested can tackle this).
Hardest part seems to be sorting out how this should be specified in context of each compression method having different ranges and defaults. But I think they all support a basic notion of integer level so this seems workable...
As for zstd, implementing support for it is likely also rather straightforward -- I haven't seen it's API but AFAIK they are all loosely similar. I was able to add brotli support pretty easily, for example, and I'd never used it's API before.
I can't promise support for every compression technique will be eagerly merged but zstd seems reasonable addition...
In short: these features likely take only an hour or two of an interested party's dev time, so if you want this supported consider tackling it and submitting a PR! The relevant parts of Nix involved here are rather accessible and don't rely on much beyond the task at hand (and maybe source/sink abstractions).
davidak commentedon Jan 5, 2020
FYI: Arch's Switch To Zstd: ~0.8% Increase In Package Size For ~1300% Speedup In Decompression Time
So this might speed up installation of packages.
AleXoundOS commentedon Apr 14, 2020
How did they achieve only 0.8% package size increase? Impressive ratio for zstd. Maybe xz compressed package size was a factor of 0.8 compared to zstd and not percentage?
Max compression level? Looking and the zstd manual, it's not promising, affecting decompression:
Nix already uses a lot of RAM.
AleXoundOS commentedon Apr 14, 2020
The request is interesting. But the current points for xz (lzma) are saved network bandwidth and server storage costs.
If it happens that download speed is slower than decompression while both are done in a streaming fashion (currently not), then we (users) hardly win anything.
15 MiB/s is 120 Mibit/s. I wonder if many of us do really have this download speed from cache.nixos.org. So the request is more oriented towards uploading caches to private servers.
As for common users I don't know if it is tricky to implement download->decompression streaming for nix store (most notably hash validation should happen after? (but
xz -dchecks integrity too)). But this brings to a question what are we going to solve and by which means?edolstra commentedon Apr 15, 2020
Nix already does download -> decompression streaming.
yorickvP commentedon Apr 15, 2020
Yes, I get 120 mbit/s from the cache, but I think the real benefit is on the compression side, where zstd uses significantly less CPU.
nagisa commentedon Apr 15, 2020
Seconding this.
nix copyfor large outputs generally spends a ton of time just compressing and failing to saturate the uplink. Parallel compression helps (and also comes at a cost of compression ratio), but is still insufficient to saturate the uplink in certain setups.AleXoundOS commentedon Apr 15, 2020
Oh, good. My fault I haven't observe it yet.
Then it's solely the compression side benefit (contrary to Arch Linux's aims).
jonringer commentedon Nov 28, 2020
I think zstd dictionaries for storing the logs would be an interesting use case as well, we currently use bz2
I took a 728 file subset of /nix/var/log/drvs/
the base behavior with bz2 compression:
training the dictionary:
zstd --train-cover ./uncompressed/* -o dictionaryrunning
zstd -b1 -e19 -D dictionary -T4 ./uncompressed/*2934241I ran it again without the the
-T4, and it's mostly the same.even just running without a dict, just running
zstd -b1 -e19 ./uncompressed/*, zstd seems to beat bzip2 at around lvl 6 in every category.obviously, nix is not log bottle necked, but it would be nice to get some of that 17x compression ratio on logs.
Also, bzip2 maintainership has been downhill for the past decade
jonringer commentedon Nov 28, 2020
and for small files, they get compressed to almost nothing:
given, this dictionary wasn't trained on a very large dataset, so it may be "overtrained", but it does help
jyrkialakuijala commentedon Feb 16, 2021
You can use a dictionary with brotli, too. Even if you train it with zstd dictionary search.
If you make the window size the same as in zstd, and the LZ77 search is done exactly the same way, brotli will be the same speed, but ~5 % more efficient due to the context modeling (depends on your data). From purely theoretical point of view, brotli format is better-suited for high compression speed and zstd better suited for fast decompression. Brotli also has slightly better streaming properties -- not hiding as much data as zstd from the data you already received as the data is multiplexed ideally for streaming in brotli and for decoding speed in zstd.
You can control brotli's window size with --window 24 or --large_window 30.
domenkozar commentedon Feb 16, 2021
(^^ co-designer of brotli)
@jyrkialakuijala our biggest problem right now is that brotli doesn't have the magic byte for decompression detection: #3333
Since our data is compressed once and decompressed a lot of times, that still talks in favor of zstd for this use case.
jyrkialakuijala commentedon Feb 17, 2021
Oi. Brotli was made only as a data stream, not to a file format (think deflate stream vs gzip). We need to place it into a container like shared brotli.
domenkozar commentedon Feb 21, 2021
I might have a budget for this feature to get done & merged (email me at [email protected]).
Currently it seems like #3333 is the quickest way to zstd support, it needs to handle brotli as a special case as magic header detection doesn't work.
nixos-discourse commentedon Dec 12, 2022
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/switch-cache-nixos-org-to-zstd-to-fix-slow-nixos-updates-nix-downloads/23961/1
nixos-discourse commentedon Jul 3, 2024
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/switch-cache-nixos-org-to-zstd-to-fix-slow-nixos-updates-nix-downloads/23961/48