Skip to content

feat(py_image_layer): configurable default layer compression#1219

Open
thirtyseven wants to merge 1 commit into
aspect-build:mainfrom
thirtyseven:feat/layer-compression-flag
Open

feat(py_image_layer): configurable default layer compression#1219
thirtyseven wants to merge 1 commit into
aspect-build:mainfrom
thirtyseven:feat/layer-compression-flag

Conversation

@thirtyseven

Copy link
Copy Markdown

Motivation

py_image_layer always compresses layers with gzip unless a py_layer_tier pins a per-group algorithm. There's no way to flip the default (e.g. to zstd) globally without editing every tier.

Change

Adds a //py:layer_compression string_flag (gzip|zstd, default gzip). It sets the default compression for any layer that doesn't pin its own algorithm via py_layer_tier.compression:

bazel build //path:layers --@aspect_rules_py//py:layer_compression=zstd
  • Read through a private _layer_compression attr on both layer aspects and the rule, mirroring how _layer_tier is plumbed.
  • _compression_for and _declare_group_tar fall back to the flag value and derive the .tar.gz / .tar.zst extension from it, instead of hard-coding gzip.
  • Explicit per-group py_layer_tier.compression still wins over the flag.

Test

Built the //cases/oci/py_image_layer e2e case both ways:

  • default → *_default.tar.gz, *_squashed.tar.gz
  • --@aspect_rules_py//py:layer_compression=zstd*_default.tar.zst, *_squashed.tar.zst

Default behavior is unchanged (still gzip), so existing tar-listing snapshots are unaffected.

Add a //py:layer_compression string_flag (gzip|zstd, default gzip) that
sets the default compression for any py_image_layer layer that doesn't pin
its own algorithm via py_layer_tier.compression. Flip it globally with
--@aspect_rules_py//py:layer_compression=zstd.

The flag is read through a private _layer_compression attr on both layer
aspects and the rule, mirroring how _layer_tier is plumbed. _compression_for
and _declare_group_tar fall back to the flag value (and derive the .tar.gz /
.tar.zst extension from it) instead of hard-coding gzip.
@CLAassistant

CLAassistant commented Jun 30, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@xangcastle xangcastle requested a review from thesayyn June 30, 2026 21:44
Comment thread py/BUILD.bazel
# Users can set --@aspect_rules_py//py:layer_compression=zstd to change the
# default compression py_image_layer uses for any layer that doesn't pin its
# own algorithm via py_layer_tier.compression.
string_flag(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be read by layer_tier and set the default compression to this value instead of every py_image_layer deciding that.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

py_binary startup benchmark

Version Mean (ms) Median (ms) ± stddev vs BCR vs main Build (s)
BCR 1.11.7 (baseline) 178.933 175.368 ±17.989 66.15
HEAD main 56.412 56.218 ±0.860 -68.5% 10.01
This PR 56.568 56.342 ±0.770 -68.4% +0.3% 7.26

Measured with hyperfine --warmup 5 --runs 50 on Linux
Gate: PR vs HEAD main (threshold: 10%). BCR is shown only as a historical baseline.
Build time: cold bazel build //:bench with isolated output base, no disk cache.

sys.path quality

Version sys.path entries distinct site-packages roots duplicate realpaths
BCR 1.11.7 (baseline) 6 1 0
HEAD main 7 2 0
This PR 7 2 0

sys.path quality measured by bench_syspath inside the assembled venv. Duplicate realpaths indicate symlink redundancy; many distinct site-packages roots suggest an inefficient venv layout.

✅ No regression detected (PR is +0.3% vs HEAD main)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants