alastairtree / LazyCache

An easy to use thread safe in-memory caching service with a simple developer friendly API for c#
https://nuget.org/packages/LazyCache
MIT License
1.72k stars 159 forks source link

Remove async-await pair #134

Closed jnyrup closed 4 years ago

jnyrup commented 4 years ago

As GetOrAddAsync only calls the other GetOrAddAsync method with an extra null parameter it should not be necessary to await the call. This also makes up for the a missing ConfigureAwait(false) introduced in https://github.com/alastairtree/LazyCache/commit/218bd2352b1217c9bacdf35566c19ebb3c85c7fa#diff-4a28b127c5a26901c14d4513be185990R165

svengeance commented 4 years ago
Method Mean Error StdDev Ratio Gen 0 Gen 1 Gen 2 Allocated
DotNetMemoryCache_GetOrAddAsync 372.7 ns 11.15 ns 0.61 ns 1.00 0.0334 - - 280 B
LazyCache_GetOrAddAsync_Proposed 516.4 ns 16.93 ns 0.93 ns 1.39 0.0448 - - 376 B
LazyCache_GetOrAddAsync 584.4 ns 5.17 ns 0.28 ns 1.57 0.0534 - - 448 B

Here's some numbers with the proposed change as well. Good find!

jnyrup commented 4 years ago

@svengeance Thanks for providing the numbers that confirms the change.

If you're a heap allocation hunter, you might be interested in ClrHeapAllocationAnalyzer