perf(pack): default zlib level 3 for pack writer output (epic #215 S6) #35

closed colechristensen cole.christensen@gmail.com wants to merge perf/zlib-level-tuning into main
No CI

Phase 2 S6 from Anvil #215 (post-hephaestus-incident hardening epic). Quick win — backed by a benchmark, not a guess.

What changes

`Pack.Writer` now uses zlib level 3 by default (was 6) when compressing entry content. Tunable via `Application.put_env(:ex_git_objectstore, :compression_level, n)` for repos with unusual content profiles.

Why 3 — the data

`test/ex_git_objectstore/pack/writer_zlib_level_benchmark_test.exs` measures wall-clock time and pack size at levels 1, 3, 6, 9 across three input shapes:

``` text-heavy (source-file style, 400 objects, 973 KiB raw): level | time (ms) | pack (KiB) | speedup-vs-6 | size-vs-6 1 | 2.2 | 60 | 1.43x | +8.6% 3 | 2.0 | 59 | 1.54x | +7.9% 6 | 3.1 | 55 | 1.00x | 0.0% 9 | 3.1 | 55 | 1.02x | 0.0%

incompressible (random bytes, 400 objects, 2000 KiB raw): level | time (ms) | pack (KiB) | speedup-vs-6 | size-vs-6 1 | 16.9 | 2005 | 1.19x | 0.0% 3 | 16.6 | 2005 | 1.21x | 0.0% 6 | 20.2 | 2005 | 1.00x | 0.0% 9 | 20.1 | 2005 | 1.00x | 0.0%

mixed (text + binary, 1600 objects, 5956 KiB raw): level | time (ms) | pack (KiB) | speedup-vs-6 | size-vs-6 1 | 38.1 | 4131 | 1.24x | +0.2% 3 | 38.7 | 4130 | 1.22x | +0.2% 6 | 47.3 | 4122 | 1.00x | 0.0% ```

Level 3 dominates level 1 in the worst case (text-heavy: 1.54x vs 1.43x speedup, 7.9% vs 8.6% size). Versus level 6 it’s 1.22–1.54x faster across the board, with at most an 8% pack-size penalty on the most-compressible content and essentially zero penalty on the realistic mixed case.

Fetch responses are ephemeral — clients re-pack the bytes locally — so the size penalty isn’t worth the CPU cost. On the prod hephaestus fetch we measured this session (8867 objects, ~210 MB raw), this should knock another ~10-20% off the ~13 s pack-build wall time. Will measure post-deploy.

Tests

  • `WriterZlibLevelBenchmarkTest` (`@moduletag :benchmark`, excluded from the normal test run) — prints the table above. Run with `mix test –only benchmark`.
  • `WriterTest` new describe: verifies the env knob actually flows through to `:zlib.deflateInit` by asserting level 9 produces a strictly smaller pack than level 1 on redundant content.
  • Full library suite: 950 tests, 0 failures.

Tracks

Epic #215 / REQ-GIT-079.

Created May 14, 2026 at 14:59 UTC