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

Use Unsafe.Read<> for faster Vector ctors #804

Closed
wants to merge 1 commit into from

Conversation

benaadams
Copy link
Contributor

@benaadams benaadams commented May 5, 2016

Needs System.Runtime.CompilerServices.Unsafe added to feed

Also using Vector for validation of longer headers which is good for Content-Security-Policy and Cookie

Needs System.Runtime.CompilerServices.Unsafe
@halter73
Copy link
Member

halter73 commented May 6, 2016

Cool PR. I didn't know about the System.Runtime.CompilerServices.Unsafe package. Here is a branch I used to compare different ValidateHeaderCharacters implementations.

I had a somewhat similar implementation (TestValidateHeaderValues3) to yours (TestValidateHeaderValues5) that is much slower since it uses ToCharArray and Buffer.BlockCopy.

Here are the results I got when testing against all the fake header values:

BenchmarkDotNet=v0.9.4.0
OS=Microsoft Windows NT 6.2.9200.0
Processor=Intel(R) Core(TM) i7-3667U CPU @ 2.00GHz, ProcessorCount=4
Frequency=2435884 ticks, Resolution=410.5286 ns, Timer=TSC
HostCLR=MS.NET 4.0.30319.42000, Arch=64-bit RELEASE [RyuJIT]
JitModules=clrjit-v4.6.1078.0

Type=Program  Mode=Throughput
Method Median StdDev
TestValidateHeaderValues1 66.4891 us 3.0924 us
TestValidateHeaderValues2 84.8861 us 2.1947 us
TestValidateHeaderValues3 161.7872 us 10.0224 us
TestValidateHeaderValues4 69.0152 us 4.5343 us
TestValidateHeaderValues5 40.8759 us 2.1885 us

Here are the results I got when removing the three largest header values:

BenchmarkDotNet=v0.9.4.0
OS=Microsoft Windows NT 6.2.9200.0
Processor=Intel(R) Core(TM) i7-3667U CPU @ 2.00GHz, ProcessorCount=4
Frequency=2435884 ticks, Resolution=410.5286 ns, Timer=TSC
HostCLR=MS.NET 4.0.30319.42000, Arch=64-bit RELEASE [RyuJIT]
JitModules=clrjit-v4.6.1078.0

Type=Program  Mode=Throughput
Method Median StdDev
TestValidateHeaderValues1 569.0469 ns 53.4758 ns
TestValidateHeaderValues2 658.3479 ns 29.6889 ns
TestValidateHeaderValues3 3,111.6132 ns 533.1012 ns
TestValidateHeaderValues4 549.9138 ns 55.9223 ns
TestValidateHeaderValues5 384.3479 ns 45.7377 ns

@halter73
Copy link
Member

halter73 commented May 6, 2016

You're right that we should wait to get System.Runtime.CompilerServices.Unsafe pushed to our MyGet. Once we do that I would like to see this split into two commits. One to update our Seek methods (a benchmark for that would be great too if you could provide it), and one to update ValidateHeaderCharacters. It probably also nice to use if (Vector.IsHardwareAccelerated) in ValidateHeaderCharacters for consistency even though it isn't the major issue it once was.

@benaadams
Copy link
Contributor Author

I didn't know about the System.Runtime.CompilerServices.Unsafe package

I think it only appeared 2 days ago :)

@benaadams
Copy link
Contributor Author

Closing and have split to #811 and #812

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.

3 participants