Skip to content

Instantly share code, notes, and snippets.

@Kobzol
Last active September 19, 2025 10:41
Show Gist options
  • Select an option

  • Save Kobzol/71f040d6d3a4b356afcdde20fc47dc81 to your computer and use it in GitHub Desktop.

Select an option

Save Kobzol/71f040d6d3a4b356afcdde20fc47dc81 to your computer and use it in GitHub Desktop.
Compute results of compressing or GCing debuginfo in ELF binaries on Linux
import dataclasses
import os.path
import subprocess
import tempfile
from pathlib import Path
from typing import Literal, Optional
@dataclasses.dataclass
class Benchmark:
profile: Literal["release", "dist"]
compress: Optional[Literal["zlib", "zstd"]]
gc: bool
def is_original(self) -> bool:
return self.compress is None and not self.gc
def get_size(path: Path) -> int:
return os.path.getsize(path)
def run_benchmark(benchmark: Benchmark) -> int:
file = Path(f"/projects/it4i/hyperqueue/hq-{benchmark.profile}")
with tempfile.TemporaryDirectory() as tmpdir:
if benchmark.gc:
gc_path = Path(tmpdir) / "gc"
subprocess.run(["llvm-dwarfutil-18", str(file), str(gc_path)], check=True)
file = gc_path
if benchmark.compress is not None:
compressed_path = Path(tmpdir) / benchmark.compress
subprocess.run(["objcopy", f"--compress-debug-sections={benchmark.compress}",
str(file),
str(compressed_path)], check=True)
file = compressed_path
return get_size(file)
dist_benchmarks = []
release_benchmarks = []
for profile in ("dist", "release"):
for compress in (None, "zlib", "zstd"):
for gc in (False, True):
benchmark = Benchmark(profile=profile, compress=compress, gc=gc)
if profile == "dist":
dist_benchmarks.append((benchmark, run_benchmark(benchmark)))
else:
release_benchmarks.append((benchmark, run_benchmark(benchmark)))
print("""
| **Version** | `release` profile | `dist` profile |
|---------------|-----------------------------:|------------------------------:|
""")
for ((rel_bench, rel_size), (dist_bench, dist_size)) in zip(release_benchmarks, dist_benchmarks):
id = ""
if rel_bench.is_original():
id = "Original"
elif rel_bench.gc:
id += "GC"
if rel_bench.compress is not None:
if id != "":
id += " + "
id += rel_bench.compress
orig_rel = [size for (b, size) in release_benchmarks if b.is_original()][0]
rel_data = f"{rel_size} ({(rel_size / orig_rel) * 100:.0f}%)"
orig_dist = [size for (b, size) in dist_benchmarks if b.is_original()][0]
dist_data = f"{dist_size} ({(dist_size / orig_dist) * 100:.0f}%)"
print(f"""| {id} | {rel_data} | {dist_data} |""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment