Skip to content

Eliminate temporary byte array allocations in the static constructor of IPAddress. - #57397

Merged
danmoseley merged 2 commits into
dotnet:mainfrom
teo-tsirpanis:ipaddress-span
Aug 16, 2021
Merged

Eliminate temporary byte array allocations in the static constructor of IPAddress.#57397
danmoseley merged 2 commits into
dotnet:mainfrom
teo-tsirpanis:ipaddress-span

Conversation

@teo-tsirpanis

Copy link
Copy Markdown
Contributor

The IPAddress class has some static fields for special IP addresses that are created using constructors that take a byte array, temporarily allocating one per object (totally six byte arrays).

With this PR, these objects are created using constructors that take a ReadOnlySpan of bytes, avoiding the allocations of the temporary byte arrays.

@ghostghost added community-contribution Indicates that the PR has been added by a community member area-System.Net labels Aug 14, 2021
@ghost

Copy link
Copy Markdown

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

Issue Details

The IPAddress class has some static fields for special IP addresses that are created using constructors that take a byte array, temporarily allocating one per object (totally six byte arrays).

With this PR, these objects are created using constructors that take a ReadOnlySpan of bytes, avoiding the allocations of the temporary byte arrays.

Author:teo-tsirpanis
Assignees:-
Labels:

area-System.Net, community-contribution

Milestone:-

Comment threadsrc/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs Outdated

@stephentoubstephentoub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@teo-tsirpanis

Copy link
Copy Markdown
ContributorAuthor

Wait, just realized that IPv6Any and IPv6None are the same actually. I will alias them.

@stephentoub

Copy link
Copy Markdown
Member

Thanks.

@danmoseley
danmoseley merged commit fde6b37 into dotnet:mainAug 16, 2021
@teo-tsirpanis
teo-tsirpanis deleted the ipaddress-span branch August 16, 2021 10:36
thaystg added a commit to thaystg/runtime that referenced this pull request Aug 16, 2021
…information
# By dotnet-maestro[bot] (4) and others
# Via GitHub
* origin/main: (58 commits)
Localized file check-in by OneLocBuild Task (dotnet#57384)
[debugger][wasm] Support DebuggerProxyAttribute (dotnet#56872)
Account for type mismatch of `FIELD_LIST` members in LSRA (dotnet#57450)
Qualify `sorted_table` allocation with `nothrow` (dotnet#57467)
Rename transport packages to follow convention (dotnet#57504)
Generate proper DWARF reg num for ARM32 (dotnet#57443)
Enable System.Linq.Queryable and disable dotnet#50712 (dotnet#57464)
Mark individual tests for 51211 (dotnet#57463)
Fix Length for ReadOnlySequence created out of sliced Memory owned by MemoryManager (dotnet#57479)
Add JsonConverter.Write/ReadAsPropertyName APIs (dotnet#57302)
Remove workaround for dotnet/sdk#19482 (dotnet#57453)
Do not drain HttpContentReadStream if the connection is disposed (dotnet#57287)
[mono] Fix a few corner case overflow operations (dotnet#57407)
make use of ports in SPN optional (dotnet#57159)
Fixed H/3 stress server after the last Kestrel change (dotnet#57356)
disable a failing stress test. (dotnet#57473)
Eliminate temporary byte array allocations in the static constructor of `IPAddress`. (dotnet#57397)
Update dependencies from https://github.com/dotnet/emsdk build 20210815.1 (dotnet#57447)
[main] Update dependencies from mono/linker (dotnet#57344)
Improve serializer performance (dotnet#57327)
...
# Conflicts:
#	src/mono/wasm/debugger/BrowserDebugProxy/MemberReferenceResolver.cs
#	src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
#	src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
@karelzkarelz added this to the 6.0.0 milestone Aug 17, 2021
@ghostghost locked as resolved and limited conversation to collaborators Sep 16, 2021
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Netcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@teo-tsirpanis@stephentoub@karelz@danmoseley