BitFaster.Caching
BitFaster.Caching copied to clipboard
Shrink Position enum
trafficstars
This enables better packing (thus lower memory usage) if key/value is smaller than 8 bytes on 64bit platforms. Common case is not affected, but those with irregular key/value sizes may benefit.
It is also possible to completely eliminate this enum, and instead compare the list property to the known lists inside ConcurrentLfuCore.
Baseline
| Method | Runtime | Mean | Error | StdDev | Ratio |
|---|---|---|---|---|---|
| ConcurrentDictionary | .NET 6.0 | 7.944 ns | 0.0667 ns | 0.0557 ns | 1.00 |
| ConcurrentLfuBackground | .NET 6.0 | 27.557 ns | 0.5801 ns | 1.0896 ns | 3.44 |
| ConcurrentLfuForeround | .NET 6.0 | 57.404 ns | 0.1683 ns | 0.1492 ns | 7.22 |
| ConcurrentLfuThreadPool | .NET 6.0 | 41.997 ns | 0.5315 ns | 0.4971 ns | 5.29 |
| ConcurrentLfuNull | .NET 6.0 | 24.297 ns | 0.1353 ns | 0.1200 ns | 3.06 |
| ConcurrentDictionary | .NET Framework 4.8 | 13.707 ns | 0.0700 ns | 0.0621 ns | 1.00 |
| ConcurrentLfuBackground | .NET Framework 4.8 | 56.628 ns | 0.7347 ns | 0.6873 ns | 4.13 |
| ConcurrentLfuForeround | .NET Framework 4.8 | 95.289 ns | 0.2929 ns | 0.2597 ns | 6.95 |
| ConcurrentLfuThreadPool | .NET Framework 4.8 | 40.305 ns | 0.8291 ns | 0.9547 ns | 2.94 |
| ConcurrentLfuNull | .NET Framework 4.8 | 34.564 ns | 0.3628 ns | 0.3394 ns | 2.52 |
With shrink
| Method | Runtime | Mean | Error | StdDev | Ratio |
|---|---|---|---|---|---|
| ConcurrentDictionary | .NET 6.0 | 8.091 ns | 0.0829 ns | 0.0648 ns | 1.00 |
| ConcurrentLfuBackground | .NET 6.0 | 28.207 ns | 0.5728 ns | 1.4990 ns | 3.48 |
| ConcurrentLfuForeround | .NET 6.0 | 56.360 ns | 0.4775 ns | 0.4233 ns | 6.97 |
| ConcurrentLfuThreadPool | .NET 6.0 | 47.918 ns | 0.4211 ns | 0.3939 ns | 5.93 |
| ConcurrentLfuNull | .NET 6.0 | 23.935 ns | 0.2700 ns | 0.2526 ns | 2.96 |
| ConcurrentDictionary | .NET Framework 4.8 | 13.765 ns | 0.1813 ns | 0.1607 ns | 1.00 |
| ConcurrentLfuBackground | .NET Framework 4.8 | 58.609 ns | 0.6275 ns | 0.5870 ns | 4.26 |
| ConcurrentLfuForeround | .NET Framework 4.8 | 93.688 ns | 0.5476 ns | 0.4855 ns | 6.81 |
| ConcurrentLfuThreadPool | .NET Framework 4.8 | 40.825 ns | 0.4277 ns | 0.3571 ns | 2.96 |
| ConcurrentLfuNull | .NET Framework 4.8 | 36.484 ns | 0.3089 ns | 0.2889 ns | 2.65 |