Skip to content

Conversation

@Rob-Hague
Copy link
Collaborator

Currently an array is allocated to read each packet from the socket, followed by decryption which allocates another array for the plaintext payload. We can save one of these two allocations by adding a persistent buffer for socket receives, and allowing the cipher implementations to decrypt into the given payload array.

We can save the other allocation similarly, but in a separate change.

Comment on lines +1993 to +1971
if (_socket is { } s)
{
s.ReceiveTimeout = 0;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just moved out from the previous implementation of TrySocketRead

Currently an array is allocated to read each packet from the socket, followed by
decryption which allocates another array for the plaintext payload. We can save one
of these two allocations by adding a persistent buffer for socket receives, and
allowing the cipher implementations to decrypt into the given payload array.

We can save the other allocation similarly, but in a separate change.
@WojciechNagorski
Copy link
Collaborator

@Rob-Hague How does this affect performance?

@Rob-Hague
Copy link
Collaborator Author

I am not expecting any noticeable speed improvements (will check). I will demonstrate the memory improvements in the next PR 🙂

@Rob-Hague Rob-Hague merged commit 8712c99 into sshnet:develop Nov 21, 2025
11 of 12 checks passed
@Rob-Hague Rob-Hague deleted the sessionbuffer branch November 21, 2025 20:21
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