Skip to content

Remove a couple allocations from Socket.Connect/Bind/etc.#32271

Merged
stephentoub merged 1 commit intodotnet:masterfrom
stephentoub:connectalloc
Feb 14, 2020
Merged

Remove a couple allocations from Socket.Connect/Bind/etc.#32271
stephentoub merged 1 commit intodotnet:masterfrom
stephentoub:connectalloc

Conversation

@stephentoub
Copy link
Member

@stephentoub stephentoub commented Feb 14, 2020

The Socket implementation calls the internal SnapshotAndSerialize method on a bunch of code paths, like Connect, Bind, etc. The "snapshot" part of the name comes from the time of CAS (thanks for the hint, @GrabYourPitchforks), and the implementation needed to clone the instance to make security decisions. We no longer make such decisions, but we're still cloning the objects. We can stop doing that. The main change is just a few lines; I then deleted a dead function it left behind, and renamed the SnapshotAndSerialize method, which is no longer snapshotting.

From a microbenchmark doing var s = new Socket(...); s.Connect(...); a thousand times...

Before:
image

After:
image

cc: @dotnet/ncl

The Socket implementation calls the internal SnapshotAndSerialize method on a bunch of code paths, like Connect, Bind, etc.  The "snapshot" part of the name comes from the time of CAS, and the implementation needed to clone the instance to make security decisions.  We no longer make such decisions, but we're still cloning the objects.  We can stop doing that.
@stephentoub stephentoub added this to the 5.0 milestone Feb 14, 2020
@stephentoub stephentoub merged commit 8f546c9 into dotnet:master Feb 14, 2020
@stephentoub stephentoub deleted the connectalloc branch February 14, 2020 16:09
@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants