feat: vendor russh-sftp with serde_bytes perf fix#188
Merged
inureyes merged 2 commits intolablup:mainfrom Apr 29, 2026
Merged
Conversation
Add `crates/bssh-russh-sftp`, a temporary fork of upstream `russh-sftp` following the same pattern as the existing `crates/bssh-russh`. The only functional change versus upstream v2.1.1 is a `#[serde(with = "serde_bytes")]` annotation on `protocol::Write::data` and `protocol::Data::data`, plus a wire-compatible `serialize_bytes` implementation in `ser.rs`. Without it, `#[derive(Deserialize)]` for `Vec<u8>` dispatches to `deserialize_seq` and parses the SFTP payload one byte at a time — `perf` shows ~42% of server CPU in `VecVisitor::visit_seq` during 1 GiB uploads. The annotation routes through the existing bulk `try_get_bytes` path in the crate's own Deserializer, which is already implemented. Measured impact on a CPU-bound host (Xeon Silver 4214) with an OpenSSH client performing a 1 GiB SFTP upload: - upstream russh-sftp 2.1.1: 74.8 MiB/s - this fork: 96.4 MiB/s (+29%) OpenSSH `sftp-server` on the same host measures ~101 MiB/s, so the gap narrows from ~26% to ~5%. Upstream russh-sftp has had no commits since its v2.1.1 bump (2025-04-18) and two download-perf issues (lablup#55 closed without root cause, lablup#70 open) sit unanswered, so the fix lives here until upstream activity resumes. `sync-upstream.sh` and `create-patch.sh` mirror the `bssh-russh` tooling so future syncs are mechanical. The top-level dependency is switched from `russh-sftp = "2.1.1"` to `russh-sftp = { package = "bssh-russh-sftp", version = "2.1.1", path = "crates/bssh-russh-sftp" }` so every `use russh_sftp::...` import in bssh continues to work unchanged.
f054871 to
7d7dcbf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
russh-sftpintocrates/bssh-russh-sftpfollowing the same pattern as the existingcrates/bssh-russh(sync-upstream.sh,create-patch.sh, andpatches/).serde_bytestoprotocol::Write::dataandprotocol::Data::dataso SFTP binary payloads are serialized/deserialized through the bulk byte-buffer path instead of serde's byte-by-byteVecVisitorpath.russh-sftpdependency to the vendored package. Existinguse russh_sftp::...imports continue to work through Cargo'spackage = "bssh-russh-sftp"alias.Motivation
perf recordon the server side of a 1 GiB SFTP upload against unmodifiedbssh-servershows:Crypto is not the bottleneck. The
WriteandDataSFTP packets carrydata: Vec<u8>, and the default derived serde path reads those payloads one byte at a time. For large uploads that means the server spends substantial CPU in generic serde dispatch rather than packet I/O.The vendored crate keeps the SFTP wire format unchanged:
u32 length + bytes. The change only routes byte vectors through serde's bytes API so the existing packet framing can be handled in bulk.Review Follow-up
After reviewing this PR for correctness, security, and performance, the follow-up commit adds these hardening changes:
deserialize_byte_bufdirectly withvisit_byte_buf(self.input.try_get_bytes()?), avoiding an extravisit_bytescopy on the optimized path.u32conversions instead of truncatingusizewithas u32.SSH_FXP_WRITEandSSH_FXP_DATAto verify theserde_bytespath still emitsu32 length + bytespayloads.russh-sftp->bssh-russh-sftpplusserde_bytes.channel_manager.rsby replacing redundant match guards with field patterns.Measured Impact
1 GiB SFTP upload, OpenSSH client ->
bssh-serveron a CPU-bound host (Xeon Silver 4214, 5 runs each):russh-sftp2.1.1bssh-russh-sftp(this PR)OpenSSH
sftp-serveron the same host measures about 101 MiB/s, so the gap shrinks from roughly 26% to roughly 5%.On a host that is already near network-bound (AMD EPYC 7742, 1 Gbps internal), both unpatched and patched runs sit around 95 MiB/s. The fix is expectedly invisible when CPU is not the limiter.
Why Vendor, Not a Git Dependency
Upstream
russh-sftphas had no commits since the v2.1.1 bump on 2025-04-18. Two related performance issues are unresolved or unresolved in root cause: #55, #70. Mirroring thebssh-russhvendoring pattern keeps the forks consistent and lets bssh ship the fix independently.If upstream merges an equivalent fix, this crate can be deleted in one follow-up change.
Test Plan
cargo test -p bssh-russh-sftp --lockedcargo test --lib --lockedcargo test --tests --locked -- --skip integration_testcargo fmt --checkcargo clippy --workspace --locked -- -D warningssftp put1 GiB file against patchedbssh-serveron CPU-bound and network-bound hosts; wire format compatible with stock OpenSSH client