Skip to content
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

SslStream should avoid copying read buffer data when it already has another frame to process #49086

Closed
geoffkizer opened this issue Mar 3, 2021 · 6 comments
Assignees
Labels
Milestone

Comments

@geoffkizer
Copy link
Contributor

The logic in SslStream.ReadAsyncInternal calls ResetReadBuffer whenever it finishes processing the previous decrypted frame and thus needs to decrypt another frame. However, this is unnecessarily aggressive. We should only do this when we are about to actually issue a read against the underlying stream. If we already have a frame buffered, then we won't read and will just process that frame immediately, which means the copy was pointless.

This might be a good reason to use ArrayBuffer here, since it simplifies some of the buffer management.

Related to #49000
Related to #49019

@geoffkizer geoffkizer added the tenet-performance Performance related issue label Mar 3, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.IO untriaged New issue has not been triaged by the area owner labels Mar 3, 2021
@ghost
Copy link

ghost commented Mar 3, 2021

Tagging subscribers to this area: @dotnet/ncl, @vcsjones
See info in area-owners.md if you want to be subscribed.

Issue Details

The logic in SslStream.ReadAsyncInternal calls ResetReadBuffer whenever it finishes processing the previous decrypted frame and thus needs to decrypt another frame. However, this is unnecessarily aggressive. We should only do this when we are about to actually issue a read against the underlying stream. If we already have a frame buffered, then we won't read and will just process that frame immediately, which means the copy was pointless.

This might be a good reason to use ArrayBuffer here, since it simplifies some of the buffer management.

Related to #49000
Related to #49019

Author: geoffkizer
Assignees: -
Labels:

area-System.Net.Security, tenet-performance, untriaged

Milestone: -

@ManickaP
Copy link
Member

ManickaP commented Mar 4, 2021

Triage: unless we have concrete complaints about this hitting customers, we might leave it to future. If this proves to be easy we might do it in 6.0.

@ManickaP ManickaP added this to the Future milestone Mar 4, 2021
@ManickaP ManickaP removed the untriaged New issue has not been triaged by the area owner label Mar 4, 2021
@wfurt
Copy link
Member

wfurt commented Mar 4, 2021

the copy is probably there to make sure there is enough room for the data. There may be enough space even with the read as the buffer may be bigger and next frame may have less then maximum size. In the other hand I'm not sure how often this would happen. I'm wondering if it would make sense add some counters so we have better visibility to some of the operations.

@wfurt wfurt self-assigned this Mar 5, 2021
@geoffkizer
Copy link
Contributor Author

@wfurt if you are optimizing this to decrypt multiple frames in a single read operation (when available), then I think this would just fall out of the work you are already doing.

That is, we should only copy the read buffer when we run out of frames to process and need to do a read on the underlying stream.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Mar 17, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jun 10, 2021
@geoffkizer
Copy link
Contributor Author

@wfurt I think you fixed this with your recent PR right?

@wfurt
Copy link
Member

wfurt commented Jul 1, 2021

fixed with #50815.

@wfurt wfurt closed this as completed Jul 1, 2021
@karelz karelz modified the milestones: Future, 6.0.0 Jul 15, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants