Repository navigation
workflows/release-binaries: Fix zstd compression - #219587
Conversation
23.1.0 was the first e2e release with zstd archives. I noticed that once it shipped they didn't have a meaningful size improvement over the pre-existing archives. Turns out this is because by default zstd compresses over a 128MB window which wasn't large enough to get meaningful savings. We now use 1GB for this which uses more memory but should take the archive from the 1.8GB that the xz release is, to ~1gb. I played around with a few options and this was the best time vs compress vs memory usage ratio. Assisted-By: codex
|
@llvm/pr-subscribers-github-workflow Author: Keith Smiley (keith) Changes23.1.0 was the first e2e release with zstd archives. I noticed that once Assisted-By: codex 2 Files Affected:
diff --git a/.github/workflows/release-binaries.yml b/.github/workflows/release-binaries.yml
index c6fd531da39b0..279ca19ffd03e 100644
--- a/.github/workflows/release-binaries.yml
+++ b/.github/workflows/release-binaries.yml
@@ -256,12 +256,12 @@ jobs:
id: setup-stage
shell: bash
run: |
- build_prefix=`pwd`
- if [ "${{ runner.os }}" = "Linux" ]; then
- sudo chown $USER:$USER /mnt/
+ build_prefix="$GITHUB_WORKSPACE"
+ if [ "$RUNNER_OS" = "Linux" ]; then
+ sudo chown "$USER:$USER" /mnt/
build_prefix=/mnt/
fi
- echo "build-prefix=$build_prefix" >> $GITHUB_OUTPUT
+ echo "build-prefix=$build_prefix" >> "$GITHUB_OUTPUT"
- name: Configure Linux/MacOS
id: build
@@ -325,14 +325,25 @@ jobs:
run: |
cat S:/llvm/utils/release/llvm_package_$($env:LLVM_VERSION)/build_$($env:BUILD_DIR_SUFFIX)/_CPack_Packages/win64/WIX/wix.log
+ # The release ref may predate the compression utility, so check it out
+ # from the same revision as this workflow.
+ - name: Checkout release compression utility
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
+ with:
+ repository: ${{ job.workflow_repository }}
+ ref: ${{ job.workflow_sha }}
+ persist-credentials: false
+ path: release-compression
+ sparse-checkout: llvm/utils/release/repack-zstd.py
+ sparse-checkout-cone-mode: false
+
- name: Create zstd compressed tarball
- shell: bash
- env:
- RELEASE_BINARY_FILENAME: ${{ needs.prepare.outputs.release-binary-filename }}
- RELEASE_BINARY_FILENAME_ZSTD: ${{ needs.prepare.outputs.release-binary-filename-zstd }}
- ZSTD: ${{ inputs.runs-on == 'windows-11-arm' && './zstd.exe' || 'zstd' }}
- run: |
- xz -dc "$RELEASE_BINARY_FILENAME" | "$ZSTD" --ultra -22 -T0 -o "$RELEASE_BINARY_FILENAME_ZSTD"
+ run: >-
+ python release-compression/llvm/utils/release/repack-zstd.py
+ --input "${{ needs.prepare.outputs.release-binary-filename }}"
+ --output "${{ needs.prepare.outputs.release-binary-filename-zstd }}"
+ --work-dir "${{ steps.setup-stage.outputs.build-prefix }}"
+ --zstd "${{ inputs.runs-on == 'windows-11-arm' && './zstd.exe' || 'zstd' }}"
- name: Generate sha256 digest for binaries
id: digest
diff --git a/llvm/utils/release/repack-zstd.py b/llvm/utils/release/repack-zstd.py
new file mode 100644
index 0000000000000..7d84ed2c60c3e
--- /dev/null
+++ b/llvm/utils/release/repack-zstd.py
@@ -0,0 +1,97 @@
+#!/usr/bin/env python3
+# ===-- repack-zstd.py ------------------------------------------------------===#
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+# ===----------------------------------------------------------------------===#
+
+import argparse
+from pathlib import Path
+import subprocess
+import sys
+import tarfile
+import tempfile
+
+ZSTD_COMPRESSION_LEVEL = 21
+ZSTD_WINDOW_LOG = 30
+ZSTD_JOB_SIZE = "1024M"
+
+
+def normalize_metadata(info: tarfile.TarInfo) -> tarfile.TarInfo:
+ info.uid = info.gid = 0
+ info.uname = info.gname = "root"
+ return info
+
+
+def repack(input_path: Path, output_path: Path, work_dir: Path, zstd: str) -> None:
+ if not input_path.name.endswith(".tar.xz"):
+ raise ValueError(f"input filename does not end in .tar.xz: {input_path}")
+
+ package_name = input_path.name.removesuffix(".tar.xz")
+ # Six workers kept the ARM64 release benchmark under 20 minutes. macOS
+ # uses fewer workers because its release runners have less memory.
+ thread_count = 4 if sys.platform == "darwin" else 6
+
+ with tempfile.TemporaryDirectory(prefix="zstd-repack-", dir=work_dir) as temp:
+ temp_dir = Path(temp)
+ extract_dir = temp_dir / "contents"
+ extract_dir.mkdir()
+
+ with tarfile.open(input_path, "r:xz") as archive:
+ archive.extractall(extract_dir, filter="data")
+
+ package_dir = extract_dir / package_name
+ if not package_dir.is_dir():
+ raise ValueError(f"archive does not contain {package_name}/")
+
+ uncompressed_tar = temp_dir / f"{package_name}.tar"
+ with tarfile.open(
+ uncompressed_tar, "w", format=tarfile.GNU_FORMAT, dereference=False
+ ) as archive:
+ # TarFile.add() visits directory contents in sorted order.
+ archive.add(
+ package_dir,
+ arcname=package_name,
+ filter=normalize_metadata,
+ )
+
+ subprocess.run(
+ [
+ zstd,
+ "--ultra",
+ f"-{ZSTD_COMPRESSION_LEVEL}",
+ # A 1 GiB window captures duplicate code across the large,
+ # statically linked tools. Match the job size to the window.
+ f"--long={ZSTD_WINDOW_LOG}",
+ f"-T{thread_count}",
+ f"-B{ZSTD_JOB_SIZE}",
+ str(uncompressed_tar),
+ "-o",
+ str(output_path),
+ ],
+ check=True,
+ )
+
+
+def main() -> None:
+ parser = argparse.ArgumentParser(
+ description="Repack a release tar.xz as a name-sorted tar.zst"
+ )
+ parser.add_argument("--input", type=Path, required=True)
+ parser.add_argument("--output", type=Path, required=True)
+ parser.add_argument("--work-dir", type=Path, required=True)
+ parser.add_argument("--zstd", default="zstd")
+ args = parser.parse_args()
+
+ repack(
+ args.input.resolve(),
+ args.output.resolve(),
+ args.work_dir.resolve(),
+ args.zstd,
+ )
+
+
+if __name__ == "__main__":
+ main()
|
|
in the end the window is really the most important part. we could save another 30mb or so by re-compressing from an entirely unarchived directory but i don't think it's worth it for the maintenance of the scripts |
I think we're good here, but the windows job timed out, it looks like the job is on the limit regardless of this change? what's the rec? should we bump that timeout? 😬 |
tstellar
left a comment
There was a problem hiding this comment.
LGTM. We can't bump the timeout for that job. I've been working on other ways to speed it up.
|
/cherry-pick 9f51fa4 |
Error: Command failed due to missing milestone. |
|
/cherry-pick 9f51fa4 |
|
/pull-request #222172 |
23.1.0 was the first e2e release with zstd archives. I noticed that once it shipped they didn't have a meaningful size improvement over the pre-existing archives. Turns out this is because by default zstd compresses over a 128MB window which wasn't large enough to get meaningful savings. We now use 1GB for this which uses more memory but should take the archive from the 1.8GB that the xz release is, to ~1gb. I played around with a few options and this was the best time vs compress vs memory usage ratio. Assisted-By: codex
23.1.0 was the first e2e release with zstd archives. I noticed that once it shipped they didn't have a meaningful size improvement over the pre-existing archives. Turns out this is because by default zstd compresses over a 128MB window which wasn't large enough to get meaningful savings. We now use 1GB for this which uses more memory but should take the archive from the 1.8GB that the xz release is, to ~1gb. I played around with a few options and this was the best time vs compress vs memory usage ratio. Assisted-By: codex (cherry picked from commit 9f51fa4)
The official LLVM 23.1.0-23.1.2 Linux lld links ICU 70 dynamically and only runs on Ubuntu 22.04 (llvm/llvm-project#215764), so link with the host ld on Linux as on macOS. Stay on 23.1.1 so toolchains_llvm's default .tar.zst archives work: from 23.1.2 (llvm/llvm-project#219587) they use a 1 GiB window, beyond Bazel's 128 MiB zstd limit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The official LLVM 23.1.0-23.1.2 Linux lld links ICU 70 dynamically and only runs on Ubuntu 22.04 (llvm/llvm-project#215764), so link with the host ld on Linux as on macOS. Stay on 23.1.1 so toolchains_llvm's default .tar.zst archives work: from 23.1.2 (llvm/llvm-project#219587) they use a 1 GiB window, beyond Bazel's 128 MiB zstd limit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
23.1.0 was the first e2e release with zstd archives. I noticed that once
it shipped they didn't have a meaningful size improvement over the
pre-existing archives. Turns out this is because by default zstd
compresses over a 128MB window which wasn't large enough to get
meaningful savings. We now use 1GB for this which uses more memory but
should take the archive from the 1.8GB that the xz release is, to ~1gb.
I played around with a few options and this was the best time vs
compress vs memory usage ratio.
Assisted-By: codex