Skip to content

perf: optimize large file copy with direct write and adaptive 1MB buffers - #2738

Merged
oferchen merged 5 commits into
masterfrom
perf/large-file-copy-optimization
Mar 16, 2026
Merged

oferchen merged 5 commits into
masterfrom
perf/large-file-copy-optimization

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Auto-enable direct write for initial copies when destination doesn't exist (no --partial, no --delay-updates). Writes directly to final path, skipping temp-file creation and rename - eliminates 2 syscalls per file and avoids double inode allocation on tmpfs.
  • Add 1MB buffer tier for files >= 256MB in both engine and transfer crates. For a 1GB file on the read/write fallback path, this halves syscall count (1024 vs 2048 read+write pairs).
  • Update README: consolidate status table by component, add What's New for v0.5.9 (since v0.5.8), trim interop/architecture sections, add Elad to acknowledgements.

Test plan

  • CI passes (fmt, clippy, nextest on all platforms)
  • Interop tests pass (direct write produces identical output to temp-file path)
  • Golden byte tests unaffected (wire format unchanged)
  • Buffer pool tests updated for new ADAPTIVE_BUFFER_HUGE tier
  • Benchmark shows improvement for 1GB initial sync scenario

For a 1GB file, the read/write fallback path now uses 1024 read+write
pairs instead of 2048 with the previous 512KB maximum. Both the engine
crate (local copy) and transfer crate (remote transfers) gain the new
tier, keeping adaptive buffer sizing consistent across all transfer
modes.
…stination

When the destination file does not exist and neither --partial nor
--delay-updates is active, write directly to the final path instead
of creating a temp file and renaming. This eliminates two syscalls
(temp-file create + rename) per file and avoids double inode allocation
on filesystems like tmpfs.

Also updates README.md: consolidates status table by component,
adds What's New section for v0.5.9 changes since v0.5.8, trims
interop and architecture sections for brevity, adds Elad to
acknowledgements.
When --temp-dir is configured, always use the temp-file + rename
pattern even for initial copies, so the user's staging directory
preference is honored.
Upstream rsync's temp file + rename protects existing destinations from
corruption on interruption. When no destination exists, there is nothing
to protect - upstream's cleanup (unlink temp) produces the same outcome
as our remove_incomplete_destination(). Direct write is therefore
equally robust for initial copies.

Guarded by: no existing file, no --partial, no --delay-updates, no
--temp-dir. create_new(true) prevents races with concurrent writers.

Also removes direct-write from README What's New since the performance
difference is negligible for large files.
@oferchen
oferchen merged commit 8326249 into master Mar 16, 2026
37 checks passed
@oferchen
oferchen deleted the perf/large-file-copy-optimization branch March 16, 2026 16:22
oferchen added a commit that referenced this pull request May 1, 2026
…fers (#2738)

* perf: add 1MB buffer tier for files >= 256MB to reduce syscall count

For a 1GB file, the read/write fallback path now uses 1024 read+write
pairs instead of 2048 with the previous 512KB maximum. Both the engine
crate (local copy) and transfer crate (remote transfers) gain the new
tier, keeping adaptive buffer sizing consistent across all transfer
modes.

* perf: auto-enable direct write for initial copies without existing destination

When the destination file does not exist and neither --partial nor
--delay-updates is active, write directly to the final path instead
of creating a temp file and renaming. This eliminates two syscalls
(temp-file create + rename) per file and avoids double inode allocation
on filesystems like tmpfs.

Also updates README.md: consolidates status table by component,
adds What's New section for v0.5.9 changes since v0.5.8, trims
interop and architecture sections for brevity, adds Elad to
acknowledgements.

* style: fix cargo fmt formatting in adaptive buffer tests

* fix: respect custom temp directory in direct-write path

When --temp-dir is configured, always use the temp-file + rename
pattern even for initial copies, so the user's staging directory
preference is honored.

* perf: direct write for initial copies with upstream robustness parity

Upstream rsync's temp file + rename protects existing destinations from
corruption on interruption. When no destination exists, there is nothing
to protect - upstream's cleanup (unlink temp) produces the same outcome
as our remove_incomplete_destination(). Direct write is therefore
equally robust for initial copies.

Guarded by: no existing file, no --partial, no --delay-updates, no
--temp-dir. create_new(true) prevents races with concurrent writers.

Also removes direct-write from README What's New since the performance
difference is negligible for large files.
oferchen added a commit that referenced this pull request May 5, 2026
…fers (#2738)

* perf: add 1MB buffer tier for files >= 256MB to reduce syscall count

For a 1GB file, the read/write fallback path now uses 1024 read+write
pairs instead of 2048 with the previous 512KB maximum. Both the engine
crate (local copy) and transfer crate (remote transfers) gain the new
tier, keeping adaptive buffer sizing consistent across all transfer
modes.

* perf: auto-enable direct write for initial copies without existing destination

When the destination file does not exist and neither --partial nor
--delay-updates is active, write directly to the final path instead
of creating a temp file and renaming. This eliminates two syscalls
(temp-file create + rename) per file and avoids double inode allocation
on filesystems like tmpfs.

Also updates README.md: consolidates status table by component,
adds What's New section for v0.5.9 changes since v0.5.8, trims
interop and architecture sections for brevity, adds Elad to
acknowledgements.

* style: fix cargo fmt formatting in adaptive buffer tests

* fix: respect custom temp directory in direct-write path

When --temp-dir is configured, always use the temp-file + rename
pattern even for initial copies, so the user's staging directory
preference is honored.

* perf: direct write for initial copies with upstream robustness parity

Upstream rsync's temp file + rename protects existing destinations from
corruption on interruption. When no destination exists, there is nothing
to protect - upstream's cleanup (unlink temp) produces the same outcome
as our remove_incomplete_destination(). Direct write is therefore
equally robust for initial copies.

Guarded by: no existing file, no --partial, no --delay-updates, no
--temp-dir. create_new(true) prevents races with concurrent writers.

Also removes direct-write from README What's New since the performance
difference is negligible for large files.
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