aspnet / Routing

[Archived] Middleware for routing requests to application logic. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
272 stars 122 forks source link

Improve performance and reduce allocations in RouteValuesAddressScheme. #879

Closed drieseng closed 5 years ago

drieseng commented 5 years ago

Improve performance and reduce allocations in RouteValuesAddressScheme. Improve test coverage for RouteValuesAddressScheme.

BenchmarkDotNet=v0.10.13, OS=Windows 10.0.17134
Intel Core i7-6700K CPU 4.00GHz (Skylake), 1 CPU, 8 logical cores and 4 physical cores
Frequency=3914069 Hz, Resolution=255.4886 ns, Timer=TSC
.NET Core SDK=2.2.100-preview2-009404
  [Host]     : .NET Core 2.2.0-preview3-27008-03 (CoreCLR 4.6.27008.03, CoreFX 4.6.27008.03), 64bit RyuJIT
  Job-LQOJYP : .NET Core 2.2.0-preview3-27008-03 (CoreCLR 4.6.27008.03, CoreFX 4.6.27008.03), 64bit RyuJIT

Runtime=Core  Server=True  Toolchain=.NET Core 2.2  
RunStrategy=Throughput  

Before:

Method Mean Error StdDev Op/s Gen 0 Allocated
Ctor 9,098.62 ns 104.4542 ns 97.7065 ns 109,906.8 0.1373 12208 B
FindEndpoints_LookUpByRouteName_MultipleMatches 335.72 ns 3.6845 ns 3.2662 ns 2,978,645.8 0.0043 400 B
FindEndpoints_LookUpByRouteName_SingleMatch 267.14 ns 2.7361 ns 2.5594 ns 3,743,322.7 0.0043 400 B
FindEndpoints_LookUpByRouteName_NoMatch 94.50 ns 0.6990 ns 0.6539 ns 10,582,294.7 0.0004 40 B

After:

Method Mean Error StdDev Op/s Gen 0 Allocated
Ctor 8,541.42 ns 22.0434 ns 20.6195 ns 117,076.6 0.1221 12056 B
FindEndpoints_LookUpByRouteName_MultipleMatches 193.14 ns 0.9645 ns 0.9022 ns 5,177,497.2 0.0017 160 B
FindEndpoints_LookUpByRouteName_SingleMatch 170.75 ns 0.1704 ns 0.1594 ns 5,856,541.3 0.0012 104 B
FindEndpoints_LookUpByRouteName_NoMatch 98.36 ns 0.1734 ns 0.1622 ns 10,167,237.4 0.0004 40 B

Benchmark is available here

Note: There's a very small performance regression in case there's no match found.

drieseng commented 5 years ago

I'm looking into the test failure.