bazelbuild / rules_pkg

Bazel rules for creating packages of many types (zip, tar, deb, rpm, ...)
Apache License 2.0
216 stars 174 forks source link

Use Gzip compress level 6 #720

Closed pauldraper closed 1 year ago

pauldraper commented 1 year ago

Much faster and comparable quality to level 9

In the example below, level 9 (max) compression is 2% smaller and 50% slower compared to level 6. This is why most gzip implementations default to level 6.


BUILD.bazel

load("@rules_pkg//pkg:tar.bzl", "pkg_tar")

pkg_tar(
    name = "tar",
    extension = "tar.gz",
    srcs = ["@src//:src"],
)

WORKSPACE.bazel

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

local_repository(
    name = "rules_pkg",
    path = "../rules_pkg",
)

load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")

rules_pkg_dependencies()

http_archive(
    build_file_content = """
filegroup(
    name = "src",
    srcs = glob(["**/*"]),
    visibility = ["//visibility:public"],
)
""".strip(),
    name = "src",
    url = "https://github.com/torvalds/linux/archive/c1a515d3c0270628df8ae5f5118ba859b85464a2.zip",
    sha256 = "33e032d6022e19c1b07ff122848b34f2f9e54e3202adb6f14da344b21f01b11a",
)

Level 6: 183MB, 36s

Level 9: 179MB, 54s


(FYI, as a note for anyone caring about performance, using an external gzip binary cut the time by a further 6s.)