feat: vendor russh-sftp with serde_bytes perf fix#188
Open
Yaminyam wants to merge 1 commit intolablup:mainfrom
Open
feat: vendor russh-sftp with serde_bytes perf fix#188Yaminyam wants to merge 1 commit intolablup:mainfrom
Yaminyam wants to merge 1 commit intolablup:mainfrom
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.
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 + patches/).serde_bytesannotation toprotocol::Write::dataandprotocol::Data::data, plus a wire-compatibleserialize_bytesimpl inser.rs. This is the only functional change versus upstream v2.1.1.russh-sftpdependency to use the vendored package. Alluse russh_sftp::...imports in bssh continue to work unchanged viapackage = "bssh-russh-sftp".Motivation
perf recordon the server side of a 1 GiB SFTP upload against unmodifiedbssh-servershows:Crypto is not the bottleneck. The
WriteandDataSFTP packets each carrydata: Vec<u8>, which with#[derive(Deserialize)]dispatches through serde's genericdeserialize_seq— reading the SFTP payload one byte at a time viaVecVisitor. For a 1 GiB upload that is ~10^9 visitor dispatches.Annotating the fields with
#[serde(with = "serde_bytes")]routesVec<u8>throughdeserialize_byte_buf, which the crate's ownDeserializeralready implements as a singletry_get_bytes(u32 length + bulkcopy_to_bytes). Symmetrically,Serializer::serialize_bytes— previously aBadMessageerror — is implemented with the sameu32 len + bytesframing the existingdeserialize_seqpath was producing, so the wire format is unchanged.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 ~101 MiB/s, so the gap shrinks from ~26% to ~5%.On a host that is already near network-bound (AMD EPYC 7742, 1 Gbps internal) both unpatched and patched runs sit at ~95 MiB/s — the fix is invisible when CPU is not the limiter, as expected.
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: #55 (closed, no root cause), #70 (open). Mirroring thebssh-russhvendoring pattern keeps the two forks consistent and lets us ship independently of upstream.If/when upstream merges an equivalent fix this crate can be deleted in one commit.
Test plan
cargo fmt --checkcargo clippy --workspace -- -D warningscargo check -p bssh-russh-sftpcargo check -p bsshsftp put1 GiB file againstbssh-serverrunning the patched binary on two different hosts (network-bound and CPU-bound), wire format verified compatible with stock OpenSSH clientcargo test --lib,cargo test --tests --skip integration_test)🤖 Generated with Claude Code