Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Faster CopyFromAscii #1308

Closed
wants to merge 6 commits into from
Closed

Faster CopyFromAscii #1308

wants to merge 6 commits into from

Conversation

benaadams
Copy link
Contributor

@benaadams benaadams commented Jan 14, 2017

Copy ulong per loop, less variable comparison, less variable changes, split multiblock into own path

Before

        Method |                 Type |          Mean |        Median |           RPS |
-------------- |--------------------- |-------------- |-------------- |-------------- |
 OutputHeaders |            Plaintext |   145.7818 ns |   146.7516 ns |  6,859,565.59 |
 OutputHeaders |               Common |   835.2836 ns |   842.3482 ns |  1,197,198.13 |
 OutputHeaders |              Unknown | 1,207.1645 ns | 1,198.2950 ns |    828,387.52 |

After

        Method |                 Type |          Mean |        Median |           RPS |
-------------- |--------------------- |-------------- |-------------- |-------------- |
 OutputHeaders |            Plaintext |   141.5104 ns |   141.8268 ns |  7,066,619.65 |
 OutputHeaders |               Common |   750.0226 ns |   748.9297 ns |  1,333,293.11 |
 OutputHeaders |              Unknown | 1,089.1873 ns | 1,089.6819 ns |    918,115.78 |

Also added test for the function...

@mharthoorn
Copy link

Shift8Idenitity should probably be Shift8Identity

@benaadams
Copy link
Contributor Author

PRing a variant of this to coreclr dotnet/coreclr#8969 as then will effect all serialization (json, mvc etc)

@@ -1214,6 +1214,71 @@ public void TestGetAsciiStringEscaped(string input, string expected, int maxChar
}
}

[Fact]
public unsafe void TestCopyFromAscii()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to see some boundary testing here, since you're copying 8 bytes at a time and then whatever is left.

@@ -21,6 +21,9 @@ public struct MemoryPoolIterator
0x02ul << 40 |
0x01ul << 48 ) + 1;

const int Shift16Shift24 = 256 * 256 * 256 + 256 * 256;
const int Shift8Idenitity = 256 + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

As pointed out my @mharthoorn, Shift8Identity.

@benaadams
Copy link
Contributor Author

Rebased + sp

Need to add boundary testing

@benaadams
Copy link
Contributor Author

Added large boundary test range; shared parsing between single and multi block; added 64/32 bit split and alignment processing.

Probably need to rebench

@benaadams
Copy link
Contributor Author

Added benchmarks

Before

        Method |                 Type |          Mean |        Median |           RPS |
-------------- |--------------------- |-------------- |-------------- |-------------- |
 OutputHeaders |               Common |   835.2836 ns |   842.3482 ns |  1,197,198.13 |
 OutputHeaders | ContentLengthNumeric |    79.6277 ns |    79.6925 ns | 12,558,439.91 |
 OutputHeaders |  ContentLengthString |    73.9253 ns |    74.7080 ns | 13,527,176.51 |
 OutputHeaders |            Plaintext |   145.7818 ns |   146.7516 ns |  6,859,565.59 |
 OutputHeaders |              Unknown | 1,207.1645 ns | 1,198.2950 ns |    828,387.52 |

After

        Method |                 Type |          Mean |        Median |           RPS |
-------------- |--------------------- |-------------- |-------------- |-------------- |
 OutputHeaders |               Common |   750.0226 ns |   748.9297 ns |  1,333,293.11 |
 OutputHeaders | ContentLengthNumeric |    77.5455 ns |    77.7948 ns | 12,895,660.83 |
 OutputHeaders |  ContentLengthString |    74.9223 ns |    75.2811 ns | 13,347,169.60 |
 OutputHeaders |            Plaintext |   141.5104 ns |   141.8268 ns |  7,066,619.65 |
 OutputHeaders |              Unknown | 1,089.1873 ns | 1,089.6819 ns |    918,115.78 |

@@ -21,9 +21,6 @@ public struct MemoryPoolIterator
0x02ul << 40 |
0x01ul << 48 ) + 1;

const int Shift16Shift24 = 256 * 256 * 256 + 256 * 256;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@benaadams benaadams closed this Mar 18, 2017
@benaadams benaadams deleted the CopyFromAscii branch March 27, 2018 05:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants