This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Remove allocations from Dns.*#41061
Merged
stephentoub merged 1 commit intodotnet:masterfrom Sep 17, 2019
Merged
Conversation
jkotas
reviewed
Sep 12, 2019
jkotas
reviewed
Sep 12, 2019
fdc2ab7 to
bb24957
Compare
geoffkizer
reviewed
Sep 12, 2019
geoffkizer
reviewed
Sep 12, 2019
geoffkizer
reviewed
Sep 12, 2019
geoffkizer
reviewed
Sep 12, 2019
geoffkizer
reviewed
Sep 12, 2019
geoffkizer
reviewed
Sep 12, 2019
geoffkizer
reviewed
Sep 12, 2019
geoffkizer
reviewed
Sep 12, 2019
geoffkizer
reviewed
Sep 12, 2019
geoffkizer
reviewed
Sep 12, 2019
geoffkizer
reviewed
Sep 12, 2019
5c3ed45 to
6e82b2b
Compare
davidsh
approved these changes
Sep 16, 2019
8074004 to
f2dd764
Compare
This started as an effort to reduce the size of System.Net.NameResolution.dll when publishing a trimmed app. It's not that big to begin with, but it's carrying around a copy of all of the IAsyncResult helper types, because the Get*Async methods are currently wrappers for the Begin/End* methods. This PR inverts that, wrapping the Begin/End* methods instead around the Get*Async methods, using the same TaskToApm helper we use in other places in corefx for the same purpose. This makes the Get*Async methods faster and lighterweight, but it does increase the number/amount of allocation in the Begin/End* APIs. Since these are considered legacy, I normally would consider that a good trade, however we still use these Begin/End methods in a few places in System.Net.Sockets, and I didn't want to regress those use cases. So, this also then trims some additional fat, which helps the Get*Async cases even further, and gets the Begin/End* to be even better than before the change. This includes not allocating an IPHostEntry when we're just going to unwrap it and return its addresses, computing the exact IPAddress[] size we need rather than using a List<> to grow it and ToArray to create the actual array, avoiding creating the HostName if we don't need it, and avoiding an unnecessary SafeHandle allocation. As part of this, I also noticed that we had some bugs in how some of our interop structures on Windows were defined. In particular, fields that in the native types were size_t were defined as int rather than IntPtr in the managed code. It appears we were saved by padding, but I fixed it regardless. And as long as I was changing pretty much everything else, where I was touching code I also cleaned up some legacy style stuff.
f2dd764 to
fa8d175
Compare
Dotnet-GitSync-Bot
pushed a commit
to Dotnet-GitSync-Bot/coreclr
that referenced
this pull request
Sep 17, 2019
This started as an effort to reduce the size of System.Net.NameResolution.dll when publishing a trimmed app. It's not that big to begin with, but it's carrying around a copy of all of the IAsyncResult helper types, because the Get*Async methods are currently wrappers for the Begin/End* methods. This PR inverts that, wrapping the Begin/End* methods instead around the Get*Async methods, using the same TaskToApm helper we use in other places in corefx for the same purpose. This makes the Get*Async methods faster and lighterweight, but it does increase the number/amount of allocation in the Begin/End* APIs. Since these are considered legacy, I normally would consider that a good trade, however we still use these Begin/End methods in a few places in System.Net.Sockets, and I didn't want to regress those use cases. So, this also then trims some additional fat, which helps the Get*Async cases even further, and gets the Begin/End* to be even better than before the change. This includes not allocating an IPHostEntry when we're just going to unwrap it and return its addresses, computing the exact IPAddress[] size we need rather than using a List<> to grow it and ToArray to create the actual array, avoiding creating the HostName if we don't need it, and avoiding an unnecessary SafeHandle allocation. As part of this, I also noticed that we had some bugs in how some of our interop structures on Windows were defined. In particular, fields that in the native types were size_t were defined as int rather than IntPtr in the managed code. It appears we were saved by padding, but I fixed it regardless. And as long as I was changing pretty much everything else, where I was touching code I also cleaned up some legacy style stuff. Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Dotnet-GitSync-Bot
pushed a commit
to Dotnet-GitSync-Bot/corert
that referenced
this pull request
Sep 17, 2019
This started as an effort to reduce the size of System.Net.NameResolution.dll when publishing a trimmed app. It's not that big to begin with, but it's carrying around a copy of all of the IAsyncResult helper types, because the Get*Async methods are currently wrappers for the Begin/End* methods. This PR inverts that, wrapping the Begin/End* methods instead around the Get*Async methods, using the same TaskToApm helper we use in other places in corefx for the same purpose. This makes the Get*Async methods faster and lighterweight, but it does increase the number/amount of allocation in the Begin/End* APIs. Since these are considered legacy, I normally would consider that a good trade, however we still use these Begin/End methods in a few places in System.Net.Sockets, and I didn't want to regress those use cases. So, this also then trims some additional fat, which helps the Get*Async cases even further, and gets the Begin/End* to be even better than before the change. This includes not allocating an IPHostEntry when we're just going to unwrap it and return its addresses, computing the exact IPAddress[] size we need rather than using a List<> to grow it and ToArray to create the actual array, avoiding creating the HostName if we don't need it, and avoiding an unnecessary SafeHandle allocation. As part of this, I also noticed that we had some bugs in how some of our interop structures on Windows were defined. In particular, fields that in the native types were size_t were defined as int rather than IntPtr in the managed code. It appears we were saved by padding, but I fixed it regardless. And as long as I was changing pretty much everything else, where I was touching code I also cleaned up some legacy style stuff. Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Dotnet-GitSync-Bot
pushed a commit
to Dotnet-GitSync-Bot/mono
that referenced
this pull request
Sep 17, 2019
This started as an effort to reduce the size of System.Net.NameResolution.dll when publishing a trimmed app. It's not that big to begin with, but it's carrying around a copy of all of the IAsyncResult helper types, because the Get*Async methods are currently wrappers for the Begin/End* methods. This PR inverts that, wrapping the Begin/End* methods instead around the Get*Async methods, using the same TaskToApm helper we use in other places in corefx for the same purpose. This makes the Get*Async methods faster and lighterweight, but it does increase the number/amount of allocation in the Begin/End* APIs. Since these are considered legacy, I normally would consider that a good trade, however we still use these Begin/End methods in a few places in System.Net.Sockets, and I didn't want to regress those use cases. So, this also then trims some additional fat, which helps the Get*Async cases even further, and gets the Begin/End* to be even better than before the change. This includes not allocating an IPHostEntry when we're just going to unwrap it and return its addresses, computing the exact IPAddress[] size we need rather than using a List<> to grow it and ToArray to create the actual array, avoiding creating the HostName if we don't need it, and avoiding an unnecessary SafeHandle allocation. As part of this, I also noticed that we had some bugs in how some of our interop structures on Windows were defined. In particular, fields that in the native types were size_t were defined as int rather than IntPtr in the managed code. It appears we were saved by padding, but I fixed it regardless. And as long as I was changing pretty much everything else, where I was touching code I also cleaned up some legacy style stuff. Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
marek-safar
pushed a commit
to mono/mono
that referenced
this pull request
Sep 17, 2019
This started as an effort to reduce the size of System.Net.NameResolution.dll when publishing a trimmed app. It's not that big to begin with, but it's carrying around a copy of all of the IAsyncResult helper types, because the Get*Async methods are currently wrappers for the Begin/End* methods. This PR inverts that, wrapping the Begin/End* methods instead around the Get*Async methods, using the same TaskToApm helper we use in other places in corefx for the same purpose. This makes the Get*Async methods faster and lighterweight, but it does increase the number/amount of allocation in the Begin/End* APIs. Since these are considered legacy, I normally would consider that a good trade, however we still use these Begin/End methods in a few places in System.Net.Sockets, and I didn't want to regress those use cases. So, this also then trims some additional fat, which helps the Get*Async cases even further, and gets the Begin/End* to be even better than before the change. This includes not allocating an IPHostEntry when we're just going to unwrap it and return its addresses, computing the exact IPAddress[] size we need rather than using a List<> to grow it and ToArray to create the actual array, avoiding creating the HostName if we don't need it, and avoiding an unnecessary SafeHandle allocation. As part of this, I also noticed that we had some bugs in how some of our interop structures on Windows were defined. In particular, fields that in the native types were size_t were defined as int rather than IntPtr in the managed code. It appears we were saved by padding, but I fixed it regardless. And as long as I was changing pretty much everything else, where I was touching code I also cleaned up some legacy style stuff. Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
jkotas
pushed a commit
to dotnet/coreclr
that referenced
this pull request
Sep 17, 2019
This started as an effort to reduce the size of System.Net.NameResolution.dll when publishing a trimmed app. It's not that big to begin with, but it's carrying around a copy of all of the IAsyncResult helper types, because the Get*Async methods are currently wrappers for the Begin/End* methods. This PR inverts that, wrapping the Begin/End* methods instead around the Get*Async methods, using the same TaskToApm helper we use in other places in corefx for the same purpose. This makes the Get*Async methods faster and lighterweight, but it does increase the number/amount of allocation in the Begin/End* APIs. Since these are considered legacy, I normally would consider that a good trade, however we still use these Begin/End methods in a few places in System.Net.Sockets, and I didn't want to regress those use cases. So, this also then trims some additional fat, which helps the Get*Async cases even further, and gets the Begin/End* to be even better than before the change. This includes not allocating an IPHostEntry when we're just going to unwrap it and return its addresses, computing the exact IPAddress[] size we need rather than using a List<> to grow it and ToArray to create the actual array, avoiding creating the HostName if we don't need it, and avoiding an unnecessary SafeHandle allocation. As part of this, I also noticed that we had some bugs in how some of our interop structures on Windows were defined. In particular, fields that in the native types were size_t were defined as int rather than IntPtr in the managed code. It appears we were saved by padding, but I fixed it regardless. And as long as I was changing pretty much everything else, where I was touching code I also cleaned up some legacy style stuff. Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
jkotas
pushed a commit
to dotnet/corert
that referenced
this pull request
Sep 17, 2019
This started as an effort to reduce the size of System.Net.NameResolution.dll when publishing a trimmed app. It's not that big to begin with, but it's carrying around a copy of all of the IAsyncResult helper types, because the Get*Async methods are currently wrappers for the Begin/End* methods. This PR inverts that, wrapping the Begin/End* methods instead around the Get*Async methods, using the same TaskToApm helper we use in other places in corefx for the same purpose. This makes the Get*Async methods faster and lighterweight, but it does increase the number/amount of allocation in the Begin/End* APIs. Since these are considered legacy, I normally would consider that a good trade, however we still use these Begin/End methods in a few places in System.Net.Sockets, and I didn't want to regress those use cases. So, this also then trims some additional fat, which helps the Get*Async cases even further, and gets the Begin/End* to be even better than before the change. This includes not allocating an IPHostEntry when we're just going to unwrap it and return its addresses, computing the exact IPAddress[] size we need rather than using a List<> to grow it and ToArray to create the actual array, avoiding creating the HostName if we don't need it, and avoiding an unnecessary SafeHandle allocation. As part of this, I also noticed that we had some bugs in how some of our interop structures on Windows were defined. In particular, fields that in the native types were size_t were defined as int rather than IntPtr in the managed code. It appears we were saved by padding, but I fixed it regardless. And as long as I was changing pretty much everything else, where I was touching code I also cleaned up some legacy style stuff. Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
picenka21
pushed a commit
to picenka21/runtime
that referenced
this pull request
Feb 18, 2022
This started as an effort to reduce the size of System.Net.NameResolution.dll when publishing a trimmed app. It's not that big to begin with, but it's carrying around a copy of all of the IAsyncResult helper types, because the Get*Async methods are currently wrappers for the Begin/End* methods. This PR inverts that, wrapping the Begin/End* methods instead around the Get*Async methods, using the same TaskToApm helper we use in other places in corefx for the same purpose. This makes the Get*Async methods faster and lighterweight, but it does increase the number/amount of allocation in the Begin/End* APIs. Since these are considered legacy, I normally would consider that a good trade, however we still use these Begin/End methods in a few places in System.Net.Sockets, and I didn't want to regress those use cases. So, this also then trims some additional fat, which helps the Get*Async cases even further, and gets the Begin/End* to be even better than before the change. This includes not allocating an IPHostEntry when we're just going to unwrap it and return its addresses, computing the exact IPAddress[] size we need rather than using a List<> to grow it and ToArray to create the actual array, avoiding creating the HostName if we don't need it, and avoiding an unnecessary SafeHandle allocation. As part of this, I also noticed that we had some bugs in how some of our interop structures on Windows were defined. In particular, fields that in the native types were size_t were defined as int rather than IntPtr in the managed code. It appears we were saved by padding, but I fixed it regardless. And as long as I was changing pretty much everything else, where I was touching code I also cleaned up some legacy style stuff. Commit migrated from dotnet/corefx@a55e95c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This started as an effort to reduce the size of
System.Net.NameResolution.dllwhen publishing a trimmed app. It's not that big to begin with, but it's carrying around a copy of all of theIAsyncResulthelper types, because theGet*Asyncmethods are currently wrappers for theBegin/End*methods.This PR inverts that, wrapping the
Begin/End*methods instead around theGet*Asyncmethods, using the sameTaskToApmhelper we use in other places in corefx for the same purpose. This makes theGet*Asyncmethods faster and lighter weight, but it does increase the number/amount of allocation in theBegin/End*APIs. Since these are considered legacy, I normally would consider that a good trade, however we still use theseBegin/Endmethods in a few places inSystem.Net.Sockets.dll(which should be fixed later), and I didn't want to regress those use cases.So, this also then trims some additional fat, which helps the
Get*Asynccases even further, and gets theBegin/End*to be even better than before the change. This includes not allocating anIPHostEntrywhen we're just going to unwrap it and return its addresses, computing the exactIPAddress[]size we need rather than using aList<>to grow it andToArrayto create the actual array, avoiding creating theHostNameif we don't need it, avoiding an unnecessarySafeHandleallocation, and avoiding a closure allocation in theTaskToApmhelpers.As part of this, I also noticed that we had some bugs in how some of our interop structures on Windows were defined. In particular, fields that in the native types were size_t were defined as int rather than IntPtr in the managed code (this appears to be carry-over from when the types were only used with the 32-bit variants). It appears we've been saved from corruption by padding, but I fixed it, regardless.
And as long as I was changing pretty much everything else, where I was touching code I also cleaned up some legacy style stuff.
Size:
In an app published as trimmed that just uses HttpClient to download a page, prior to this change, System.Net.NameResolution.dll was 30K; after this change it's 24K.
Perf: