aspnet / Security

[Archived] Middleware for security and authorization of web apps. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
1.27k stars 600 forks source link

Eliminate allocations in AuthorizationPolicy.CombineAsync with no policy #1899

Closed JamesNK closed 5 years ago

JamesNK commented 5 years ago

Used by AuthorizationMiddleware. Want to avoid allocations when there is no policy to evaluate.

Hide whitespace for best reviewing experience.

On https://github.com/aspnet/Security/pull/1894

davidfowl commented 5 years ago

Where's the before and after number

JamesNK commented 5 years ago

Note: I added caching to policy provider tasks.

Before:

       Method |     Mean |    Error |   StdDev |        Op/s |  Gen 0 | Allocated |
------------- |---------:|---------:|---------:|------------:|-------:|----------:|
 CombineAsync | 100.7 ns | 2.348 ns | 4.174 ns | 9,927,843.4 | 0.0203 |     184 B |

After:

       Method |     Mean |     Error |    StdDev |         Op/s | Allocated |
------------- |---------:|----------:|----------:|-------------:|----------:|
 CombineAsync | 57.57 ns | 0.5720 ns | 0.5351 ns | 17,371,422.1 |       0 B |