Skip to content

perf: match upstream rsync compression negotiation precedence - #2737

Merged
oferchen merged 4 commits into
masterfrom
perf/compression-negotiation-zstd-default
Mar 16, 2026
Merged

oferchen merged 4 commits into
masterfrom
perf/compression-negotiation-zstd-default

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Default compression algorithm now follows upstream rsync 3.4.1's compat.c:valid_compressions_items[] precedence: zstd > lz4 > zlibx > zlib > none
  • Fixed missing feature propagation: zstd/lz4 features now reach the protocol crate for correct negotiation advertisement
  • Switched default zlib backend from zlib-rs to zlib-ng (C library with SIMD) for older peer compatibility

Root cause: Local transfers hardcoded CompressionAlgorithm::Zlib while upstream rsync 3.4.1 negotiates zstd (confirmed via perf profiling: upstream shows ZSTD_compressStream2, oc-rsync showed deflate_medium/zng_deflate). Upstream with explicit --compress-choice=zlib takes 1457ms, proving the backends are equivalent - only the algorithm selection differed.

Benchmark (container, 157MB, 10K files, aarch64)

Mode Upstream Before After
-a (no compress) 550ms 460ms (0.84x) 460ms (0.84x)
-az (compress) 550ms 1550ms (3.2x) 635ms (1.15x)

Test plan

  • CI: fmt + clippy pass
  • CI: nextest all platforms (Linux, macOS, Windows)
  • CI: interop tests against upstream rsync 3.0.9, 3.1.3, 3.4.1
  • Verify zlib-ng compiles on all CI targets (requires cmake/cc)
  • Verify --compress-choice=zlib still works for explicit zlib selection

… lz4 > zlib)

Root cause: oc-rsync used zlib for all local transfers while upstream
rsync 3.4.1 negotiates zstd (5x faster). Three issues fixed:

1. Default compression algorithm hardcoded to Zlib instead of matching
   upstream's compat.c:valid_compressions_items[] precedence order
   (zstd > lz4 > zlibx > zlib > none).

2. Protocol crate never received zstd/lz4 feature flags - the feature
   chain went root -> core -> {engine, transfer, compress} but skipped
   protocol, so supported_compressions() never advertised zstd/lz4.

3. Switched default zlib backend from zlib-rs (pure Rust) to zlib-ng
   (C library with SIMD: SSE2, AVX2, NEON) for when zlib is needed
   with older peers, matching upstream rsync's zlib performance.

Container benchmark (157MB, 10K files, aarch64):
  Before: upstream 550ms, oc-rsync 1550ms (3.2x slower)
  After:  upstream 550ms, oc-rsync 635ms  (1.15x)
Tests that explicitly set CompressionAlgorithm::Zstd now use Zlib
instead, since zstd is the new default and --compress-choice is only
emitted for non-default algorithms.
The bandwidth limiting test verifies post-compression byte counting,
not compression algorithm selection. Pin to Zlib so the test is not
sensitive to the default algorithm changing from zlib to zstd.
The zstd wire protocol uses per-token flushing (ZSTD_e_flush) in
upstream token.c, while oc-rsync uses stream-level compression.
Until the wire framing is compatible, do not propagate zstd/lz4
features to the protocol crate - this prevents advertising them
in compression negotiation. Local transfers still use zstd via
the compress crate directly.
@oferchen
oferchen merged commit b8f6284 into master Mar 16, 2026
31 checks passed
@oferchen
oferchen deleted the perf/compression-negotiation-zstd-default branch March 16, 2026 15:09
oferchen added a commit that referenced this pull request May 1, 2026
* perf: match upstream rsync compression negotiation precedence (zstd > lz4 > zlib)

Root cause: oc-rsync used zlib for all local transfers while upstream
rsync 3.4.1 negotiates zstd (5x faster). Three issues fixed:

1. Default compression algorithm hardcoded to Zlib instead of matching
   upstream's compat.c:valid_compressions_items[] precedence order
   (zstd > lz4 > zlibx > zlib > none).

2. Protocol crate never received zstd/lz4 feature flags - the feature
   chain went root -> core -> {engine, transfer, compress} but skipped
   protocol, so supported_compressions() never advertised zstd/lz4.

3. Switched default zlib backend from zlib-rs (pure Rust) to zlib-ng
   (C library with SIMD: SSE2, AVX2, NEON) for when zlib is needed
   with older peers, matching upstream rsync's zlib performance.

Container benchmark (157MB, 10K files, aarch64):
  Before: upstream 550ms, oc-rsync 1550ms (3.2x slower)
  After:  upstream 550ms, oc-rsync 635ms  (1.15x)

* fix: update tests for zstd default compression algorithm

Tests that explicitly set CompressionAlgorithm::Zstd now use Zlib
instead, since zstd is the new default and --compress-choice is only
emitted for non-default algorithms.

* fix: use explicit Zlib in bandwidth compression test

The bandwidth limiting test verifies post-compression byte counting,
not compression algorithm selection. Pin to Zlib so the test is not
sensitive to the default algorithm changing from zlib to zstd.

* fix: do not advertise zstd/lz4 in protocol negotiation

The zstd wire protocol uses per-token flushing (ZSTD_e_flush) in
upstream token.c, while oc-rsync uses stream-level compression.
Until the wire framing is compatible, do not propagate zstd/lz4
features to the protocol crate - this prevents advertising them
in compression negotiation. Local transfers still use zstd via
the compress crate directly.
oferchen added a commit that referenced this pull request May 5, 2026
* perf: match upstream rsync compression negotiation precedence (zstd > lz4 > zlib)

Root cause: oc-rsync used zlib for all local transfers while upstream
rsync 3.4.1 negotiates zstd (5x faster). Three issues fixed:

1. Default compression algorithm hardcoded to Zlib instead of matching
   upstream's compat.c:valid_compressions_items[] precedence order
   (zstd > lz4 > zlibx > zlib > none).

2. Protocol crate never received zstd/lz4 feature flags - the feature
   chain went root -> core -> {engine, transfer, compress} but skipped
   protocol, so supported_compressions() never advertised zstd/lz4.

3. Switched default zlib backend from zlib-rs (pure Rust) to zlib-ng
   (C library with SIMD: SSE2, AVX2, NEON) for when zlib is needed
   with older peers, matching upstream rsync's zlib performance.

Container benchmark (157MB, 10K files, aarch64):
  Before: upstream 550ms, oc-rsync 1550ms (3.2x slower)
  After:  upstream 550ms, oc-rsync 635ms  (1.15x)

* fix: update tests for zstd default compression algorithm

Tests that explicitly set CompressionAlgorithm::Zstd now use Zlib
instead, since zstd is the new default and --compress-choice is only
emitted for non-default algorithms.

* fix: use explicit Zlib in bandwidth compression test

The bandwidth limiting test verifies post-compression byte counting,
not compression algorithm selection. Pin to Zlib so the test is not
sensitive to the default algorithm changing from zlib to zstd.

* fix: do not advertise zstd/lz4 in protocol negotiation

The zstd wire protocol uses per-token flushing (ZSTD_e_flush) in
upstream token.c, while oc-rsync uses stream-level compression.
Until the wire framing is compatible, do not propagate zstd/lz4
features to the protocol crate - this prevents advertising them
in compression negotiation. Local transfers still use zstd via
the compress crate directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant