Does buildkit respect the compression-level supplied in the --output parameter? #6291
-
|
I tried benchmarking the compression times of different zstd levels via buildkit and via the zstd binary and I get very different results. For example, for some higher levels, buildkit would finish building and pushing the image much faster than zstd can just compress it, and the image ends up being larger than the one compressed with the zstd binary, which leads me to believe that it does not in fact respect the supplied value. It looks to me as if buildkit uses only a few distinct levels and maps zstd levels 1-22 to these internal levels. E.g. the compression times and image sizes for levels 9-22 look pretty much identical. Can someone shed some light on this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Your insights are correct,
Original replyJust to clarify:
The support for func toZstdEncoderLevel(level int) zstd.EncoderLevel {
// map zstd compression levels to go-zstd levels
// once we also have c based implementation move this to helper pkg
if level < 0 {
return zstd.SpeedDefault
} else if level < 3 {
return zstd.SpeedFastest
} else if level < 7 {
return zstd.SpeedDefault
} else if level < 9 {
return zstd.SpeedBetterCompression
}
return zstd.SpeedBestCompression
}This logic could have been avoided by just passing the // EncoderLevelFromZstd will return an encoder level that closest matches the compression
// ratio of a specific zstd compression level.
// Many input values will provide the same compression level.
func EncoderLevelFromZstd(level int) EncoderLevel {
switch {
case level < 3:
return SpeedFastest
case level >= 3 && level < 6:
return SpeedDefault
case level >= 6 && level < 10:
return SpeedBetterCompression
default:
return SpeedBestCompression
}
}UPDATE: That method got relocated here as of current master branch, so this logic remains the same. Despite the
Better and Best levels were added Dec 2020, no change in the documented mapping since so they may no longer reflect their equivalent zstd levels compression ratio today. I've filed an issue at the Docker docs repo to try make this information easier to discover 👍 |
Beta Was this translation helpful? Give feedback.
Your insights are correct,
compression-levelis mapped to 4 compression levels fromklauspost/compress/zstd(Zstd Go implementation):compression-levelklauspost/compress/zstdlevelklauspost/compress/zstdhas expressed in Sep 2025 that there is no intent to add more than those 4 levels.compression+compression-leveldisclose the compression libraries used, but without documenting the actual mapped ranges forcompression-level(while no disclosure is provided within the buildkit docs).