Repository navigation
packing: replace greedy merge with statistical partitioning - #107
Conversation
There was a problem hiding this comment.
Code Review
This pull request replaces the existing greedy clustering algorithm for OCI layer packing with a new statistical partitioning approach inspired by rpm-ostree. The new algorithm classifies components into layers based on size outliers (using median and MAD) and stability tiers, utilizing name-based hashing for deterministic binning. Feedback identifies critical logic errors where components could be silently dropped if the layer budget is exhausted or if a stability tier is allocated zero bins. Additionally, a fix is required for the use of an unstable Rust feature in the median calculation.
|
Don't look too much at the code. This is still rough/raw from Opus. I still need to carefully go through it, but the results are encouraging. I made it sweep for optimal parameters for the FCOS and Silverblue sets (which hopefully generalizes well to non-Fedora data sets -- will try to do more validation there). |
3a357ad to
259b0a7
Compare
|
There's plenty of other container images to look at, I think |
|
Happy to turn on whatever is necessary to help! |
Switch test-arch.sh and test-self.sh to use --write-manifest-to for checking the unclaimed component size. The previous approach checked the layer size via skopeo inspect, which is inaccurate since the unclaimed component may share a layer with other components. For test-self.sh, also drop the is_chunked shortcut so that we always run chunkah and produce a manifest. Assisted-by: OpenCode (Claude Opus 4.6)
Wrap the processing loop in try/finally so that temporary localhost/tmp-chunk-src images are always removed, even if chunking fails or is interrupted mid-run. Previously these would leak and cause duplicate tag issues in subsequent runs. Assisted-by: OpenCode (Claude Opus 4.6)
Add an OpenCode skill that guides benchmarking of packing algorithm changes. Covers the full pipeline from building chunkah through analyzing layer reuse, including key pitfalls like duplicate tags and sample size sensitivity. Assisted-by: OpenCode (Claude Opus 4.6)
OpenCode respects this also, and so does Pi. Claude, as usual, does not.
8d87008 to
c3ce41b
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request replaces the existing clustering-based packing algorithm with a two-phase statistical partitioning approach designed to improve layer reuse and ensure deterministic binning. Phase 1 isolates large components as singletons using median absolute deviation, while Phase 2 categorizes remaining items into stability tiers and assigns them to bins via name-based hashing. The PR also updates E2E tests to verify component sizes through generated manifests and adds comprehensive benchmarking documentation. Feedback was provided regarding the use of DefaultHasher, which may not guarantee the intended cross-build stability across different Rust toolchains or platforms.
The old algorithm used a greedy merge approach (BinaryHeap-based,
minimizing total expected value loss per merge) which was fundamentally
unstable: small changes in input caused completely different merge
decisions, resulting in poor layer reuse across updates.
Additionally, because of its greediness, it easily fell into a local
optimum with a giant catch-all bucket with low stability and safer more
stable items in the other layers.
Replace it with a two-phase statistical partitioning approach inspired
by rpm-ostree's chunking algorithm:
- Phase 1 classifies components by size, giving large components
(linux-firmware, kernel, firefox) their own singleton layers.
- Phase 2 assigns all remaining components to bins using stability tiers
(high/mid/low) and deterministic name-based hashing, which ensures
stable bin membership across builds without needing to track prior
build state.
Also remove the stability fallback that assigned min(known)/2 to
components without stability data (xattr, bigfiles, unclaimed). These
now stay at 0.0 and are naturally handled by the stability tiers.
Benchmarked against rpm-ostree's native chunking on FCOS F43 (11
biweekly stable releases) and Silverblue F43 (3 weekly builds):
FCOS: 46.4% reuse, 916 MiB avg download uncompressed (rpm-ostree: 34.0%, 1.2 GiB)
Silverblue: 47.9% reuse, 2.8 GiB avg download uncompressed (rpm-ostree: 38.5%, 3.5 GiB)
Assisted-by: OpenCode (Claude Opus 4.6)
|
OK, I've tested this extensively now and I'm pretty satisfied with it. I've cleaned up the code a bunch and did some minor additional optimizations. This notably brings chunkah packing performance for Silverblue to parity with rpm-ostree or above it. With infinite time, it would be cool to geek out on this more and throw more tokens at other approaches, but gains would likely not be as drastic. This is good enough and certainly better than the status quo, so let's ship it. Some stats from recent runs, keeping 64 layers for parity with rpm-ostree: FCOS f43 (10 biweekly updates, 64 layers)
Silverblue f43 (10 daily updates, 64 layers)
Silverblue f43 (2 weekly updates, 64 layers)
(I did also test many other images, but not to the same extent as these.) |
|
I'm gathering more metrics on this. Man dude, this really made a difference in the buildstream builds. This is really going to help bootc adoption! cc @ahmedadan |
The old algorithm used a greedy merge approach (BinaryHeap-based,
minimizing total expected value loss per merge) which was fundamentally
unstable: small changes in input caused completely different merge
decisions, resulting in poor layer reuse across updates.
Additionally, because of its greediness, it easily fell into a local
optimum with a giant catch-all bucket with low stability and safer more
stable items in the other layers.
Replace it with a two-phase statistical partitioning approach inspired
by rpm-ostree's chunking algorithm:
(linux-firmware, kernel, firefox) their own singleton layers.
(high/mid/low) and deterministic name-based hashing, which ensures
stable bin membership across builds without needing to track prior
build state.
Also remove the stability fallback that assigned min(known)/2 to
components without stability data (xattr, bigfiles, unclaimed). These
now stay at 0.0 and are naturally handled by the stability tiers.
Benchmarked against rpm-ostree's native chunking on FCOS F43 (11
biweekly stable releases) and Silverblue F43 (3 weekly builds):
Assisted-by: OpenCode (Claude Opus 4.6)