Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
/corefxPublic archive

Reduce allocations in SslStream reading/writing by ~30%#13274

Merged
stephentoub merged 3 commits intodotnet:masterfromstephentoub:ssl_allocs
Nov 3, 2016

Conversation

@stephentoub
Copy link
Member

@stephentoubstephentoub commentedNov 2, 2016
edited
Loading

#12935 reduced allocations in SslStream reading/writing by ~70%. This PR reduces it further by another ~30% from where it was after that PR.

Before (10K reads / 10K writes):
image

After (10K reads / 10K writes):
image

Main changes:

  • Every read/write operation was allocating a new AsyncProtocolRequest. Without changing any of the plumbing through SslStream, we can take advantage of the fact that SslStream allows only a single read and a single write operation at a time, which means we can store and reuse an AsyncProtocolRequest instance for reading and one for writing, reusing the instances for all read/write operations on the stream.
  • Every read operation was boxing an Int32 result. This changes the BufferAsyncResult instance used for reads to reuse one of its existing fields to store that result, rather than storing it in the base LazyAsyncResult's object field.
  • Also took the opportunity to remove an unused field from BufferAsyncResult, though it doesn't change the size on 64-bit given the other fields on the base class.

cc:@geoffkizer,@ericeil,@davidsh,@CIPop,@benaadams,@davidfowl
Contributes tohttps://github.com/dotnet/corefx/issues/11826

HFadeel reacted with thumbs up emoji
Saves an allocation per read and write, ammortizing the costs across the whole stream's lifetime.
@stephentoubstephentoub changed the titleSsl allocsReduce allocations in SslStream reading/writing by 30%Nov 2, 2016
@stephentoubstephentoub changed the titleReduce allocations in SslStream reading/writing by 30%Reduce allocations in SslStream reading/writing by ~30%Nov 2, 2016

internalvoidCompleteUser(objectuserResult)
internalvoidCompleteUser(intuserResult)
{

Choose a reason for hiding this comment

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

nit: capitalization

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

nit: capitalization

Of what?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Oh, in the debug message below? GitHub wasn't showing that on the comment view. Will lower-case the R.

Choose a reason for hiding this comment

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

Yes, sorry for the confusion, I meant the R in the comment below.

@geoffkizer
Copy link

LGTM. Nice work.

I do think that longer-term we should revisit the async implementation pattern here and elsewhere. There are likely more wins to be had here. Even with your improvements, async objects account for ~80% of allocated bytes.

@stephentoub
Copy link
MemberAuthor

I do think that longer-term we should revisit the async implementation pattern here and elsewhere. There are likely more wins to be had here. Even with your improvements, async objects account for ~80% of allocated bytes.

Absolutely. As you suggest, this is trying to make the best of the current design. Note that the SecBufferDesc allocation per operation can also be removed with a bit of work (see my comments in#12935), at which point all allocations per operation will be due to asynchrony. Once that's removed, we'll essentially have two allocations per read/write operation, one for the IAsyncResult and one for the Task wrapping it; it'll take some work, but we should be able to get that down to one, at which point I think that's generally the best we can do with the current API shape (though for some operations, we should be able to eliminate all allocations if they complete synchronously).

@benaadams
Copy link
Member

LGTM - Excellent work! 👍

Copy link
Contributor

@davidshdavidsh left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks@stephentoub !

- Change BufferAsyncResult to allow storing int result, without adding another field- Use that in both SslStream and NegotiateStream to avoid boxing an int per read and write- Also rename AsyncProtocolRequest.CompleteWithError to CompleteUserWithError, to avoid confusion and keep it consistent with the other CompleteUser methods.
@stephentoub
Copy link
MemberAuthor

@dotnet-bot Test Outerloop Windows_NT Debug please
@dotnet-bot Test Outerloop Ubuntu14.04 Debug please

@stephentoub
Copy link
MemberAuthor

Thanks for the reviews, all.

@stephentoub
Copy link
MemberAuthor

@dotnet-bot Test OuterLoop Ubuntu14.04 Debug please ("arm32 emulator vms build and test on the main drive which is small. This is tracked with issuehttps://github.com/dotnet/coreclr/issues/6676")

@stephentoub
Copy link
MemberAuthor

@dotnet-bot Test OuterLoop Windows_NT Debug please (https://github.com/dotnet/corefx/issues/13281)

@stephentoub
Copy link
MemberAuthor

@dotnet-bot Test OuterLoop Windows_NT Debug please (https://github.com/dotnet/corefx/issues/13284)

@stephentoub
Copy link
MemberAuthor

@dotnet-bot Test OuterLoop Windows_NT Debug please (now thathttps://github.com/dotnet/corefx/issues/13284 is fixed)

@stephentoubstephentoub merged commit8b5760b intodotnet:masterNov 3, 2016
@stephentoubstephentoub deleted the ssl_allocs branchNovember 3, 2016 03:29
@karelzkarelz modified the milestone:1.2.0Dec 3, 2016
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

2 more reviewers

@geoffkizergeoffkizergeoffkizer left review comments

@davidshdavidshdavidsh approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

2.0.0

Development

Successfully merging this pull request may close these issues.

6 participants

@stephentoub@geoffkizer@benaadams@davidsh@karelz@dnfclas

[8]ページ先頭

©2009-2025 Movatter.jp