Skip to content

Applied BinaryPrimitives throughout CoreLib#37582

Merged
GrabYourPitchforks merged 5 commits intodotnet:masterfrom
bbartels:BinaryWriterRefactor
Aug 14, 2020
Merged

Applied BinaryPrimitives throughout CoreLib#37582
GrabYourPitchforks merged 5 commits intodotnet:masterfrom
bbartels:BinaryWriterRefactor

Conversation

@bbartels
Copy link
Contributor

@bbartels bbartels commented Jun 8, 2020

This PR removes manually writing individual bytes of 64 bit data types (long, ulong, double) into the _buffer array and replaces it with a single BinaryPrimitives call yielding about 9% better performance.

I've benchmarked changes of < 64 bit types to BinaryPrimitives calls, but found performance regression, hence their implementation is unchanged.

There is also an unnecessary write to the _buffer array to convert a bool to a byte. This was replaced with a direct call to WriteByte() of Stream improving performance by about 55%.

New:

Method Old New Improvement
Write_Bool 6.692 4.238 ns +58%
Write_Double 15.959 14.514 ns +10%
Write_Long 15.725 14.403 ns +9%

@bbartels
Copy link
Contributor Author

bbartels commented Jun 8, 2020

I've added a few more such instances in Guid.cs and Decimal.cs

@bbartels bbartels changed the title Applied BinaryPrimitives in BinaryWriter Applied BinaryPrimitives throughout CoreLib Jun 8, 2020
@GrabYourPitchforks GrabYourPitchforks merged commit 46a563a into dotnet:master Aug 14, 2020
@GrabYourPitchforks
Copy link
Member

CI is having trouble kicking off, but the previous run (pre-conflict resolution) was green. So we're good to go.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants