Skip to content

Commit 22b82ea

Browse files
authored
Update README.md
1 parent 6c3a675 commit 22b82ea

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

README.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# ⚡ Lightweight.Caching
22

3-
A lightweight caching library.
3+
A lightweight high performance caching library with simple cache primitives suitable for use on the hot path.
4+
5+
## Meta-programming using struct for JIT dead code removal and inlining
6+
7+
ConcurrentLru features injectable policies defined as structs. Since structs are subject to special optimizations by the JITter, the implementation is much faster than if these policies were defined as classes. Using this technique, lookups without TTL are within 15% of the speed of a ConcurrentDictionary.
8+
9+
Since DateTime.UtcNow is around 4x slower than a ConcurrentDictionary lookup, policies that involve time based expiry are significantly slower. Since these are injected as structs and the slow code is optimized away, it is possible maintain the fastest possible speed for the non-TTL policy.
10+
11+
## Perf numbers
412

513
~~~
614
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.900 (1909/November2018Update/19H2)
@@ -14,10 +22,10 @@ Job=RyuJitX64 Jit=RyuJit Platform=X64
1422
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen 0 | Gen 1 | Gen 2 | Allocated |
1523
|------------------------------ |----------:|---------:|---------:|------:|--------:|-------:|------:|------:|----------:|
1624
| DictionaryGetOrAdd | 18.65 ns | 0.384 ns | 0.341 ns | 1.00 | 0.00 | - | - | - | - |
25+
| DateTime.UtcNow | 76.31 ns | 1.373 ns | 2.805 ns | 4.07 | 0.18 | - | - | - | - |
1726
| SegmentedLruGetOrAdd | 21.62 ns | 0.262 ns | 0.218 ns | 1.16 | 0.03 | - | - | - | - |
18-
| OldLru2GetOrAdd | 370.29 ns | 6.435 ns | 5.373 ns | 19.89 | 0.50 | 0.0458 | - | - | 96 B |
19-
| ConcurrentLruGetOrAdd | 20.95 ns | 0.229 ns | 0.178 ns | 1.13 | 0.02 | - | - | - | - |
20-
| ConcurrentLruHitGetOrAdd | 36.37 ns | 0.340 ns | 0.284 ns | 1.95 | 0.04 | - | - | - | - |
27+
| ClassNoTtlPolicyGetOrAdd | 370.29 ns | 6.435 ns | 5.373 ns | 19.89 | 0.50 | 0.0458 | - | - | 96 B |
28+
| ConcurrentLruTemplGetOrAdd | 20.95 ns | 0.229 ns | 0.178 ns | 1.13 | 0.02 | - | - | - | - |
29+
| ConcurrentLruTemplHitGetOrAdd | 36.37 ns | 0.340 ns | 0.284 ns | 1.95 | 0.04 | - | - | - | - |
2130
| ConcurrentLruNoExpireGetOrAdd | 21.00 ns | 0.332 ns | 0.294 ns | 1.13 | 0.03 | - | - | - | - |
2231
| ConcurrentLruExpireGetOrAdd | 100.37 ns | 1.620 ns | 1.516 ns | 5.39 | 0.13 | - | - | - | - |
23-
| Now | 76.31 ns | 1.373 ns | 2.805 ns | 4.07 | 0.18 | - | - | - | - |

0 commit comments

Comments
 (0)