Skip to content

Use an array buffer for the sftp packet stream #1649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025

Conversation

Rob-Hague
Copy link
Collaborator

@Rob-Hague Rob-Hague commented Jun 1, 2025

The sftp packet stream runs within but independently of the channel data stream, meaning a channel data packet can contain multiple sftp packets, or an sftp packet can be split across multiple channel data packets.

Normally the packets are sized such there is a 1-to-1 relationship for efficiency. When this doesn't happen the library falls back to buffering via a List<byte>, which is not so efficient. This change uses an array-based buffer instead.

In a sample download which hit this fallback I see about a 20% reduction in memory allocated.

The sftp packet stream runs within but independently of the channel data stream,
meaning a channel data packet can contain multiple sftp packets, or an sftp packet
can be split across multiple channel data packets.

Normally the packets are sized such there is a 1-to-1 relationship for efficiency.
When this doesn't happen the library falls back to buffering via a List<byte>,
which is not so efficient. This change uses an array-based buffer instead.

In a sample download which hit this fallback I see about a 20% reduction in memory
allocated.
@Rob-Hague Rob-Hague merged commit 1f1a5fe into sshnet:develop Jun 6, 2025
4 checks passed
@Rob-Hague Rob-Hague deleted the arraysegment0 branch June 6, 2025 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants