Finding optimal 7-Zip parameters for creating a ZIP archive
We were packing our builds into ZIP archives for distribution right in TeamCity using its built-in artifact packaging. But then we decided to try to do that explicitly with 7-Zip as a dedicated build step, and that turned out to be a faster option, providing a better compression ratio too.
The only question remaining was finding the right balance between compression level and compression time.
So, the goal is to create a ZIP archive with a good balance between compression ratio and packing time using 7-Zip (on Linux). Our build artifacts are mostly binary
.dll’s and plain-text files (
Why ZIP and not 7z? Well, unfortunatelly, quite a lot of users simply won’t know what to do with a file named
some-build.7z, so we have to stick with good old ZIP.
7-Zip command line parameters
How to create a ZIP archive
$ 7z a -tzip some-build.zip some-build-artifacts
-tzip- type of archive: ZIP
Maximum compression level
$ 7z a -tzip -mx9 some-build.zip some-build-artifacts
-mx9- compression level: 9 (maximum compression)
Specific number of threads
If you won’t set the number of threads explicitly, 7-Zip seems to default to all the available threads, which I think is a good default behaviour. You can set a specific number of threads too:
$ 7z a -tzip -mx9 -mmt12 some-build.zip some-build-artifacts
-mmt12- number of threads to use: 12
If the machine has only 12 threads available, then providing
--mmt12 seems to be futile, as it will use all 12 by default anyway.
Finding optimal parameters
Now let’s see what results do we get with various combinations of compression level and numbers of threads.
- Intel Core i7-5820K
- 12 threads
|Compression||Threads||Time||Original size||Archived size|
So with default parameters the packing on this particular machine seems to be done with
mx5 compression level and all the 12 available threads.
Graphical representation of the results:
Given quite a little difference in resulting archived size and a quite huge difference in time, the option #3 is the most optimal in terms of time/compression for our case.
So, the resulting set of parameters:
$ 7z a -tzip -mx3 some-build.zip some-build-artifacts
Zuck: Just ask
Zuck: I have over 4,000 emails, pictures, addresses, SNS
smb: What? How'd you manage that one?
Zuck: People just submitted it.
Zuck: I don't know why.
Zuck: They "trust me"
Zuck: Dumb fucks