Skip to content

Conversation

@bitfaster
Copy link
Owner

@bitfaster bitfaster commented Apr 22, 2022

TimeSpan and Stopwatch don't have the same number of ticks per second on all platforms.

Therefore, introduce an adjustment coefficient to adjust the TTL stored as ticks. This computation is only done in the ctor, so the overhead is once per cache instantiation. It will have no effect on runtime performance.

Added a github action to run all unit tests on macos, and fixed the long ticks TTL policy tests so that they pass on macos.

@bitfaster bitfaster changed the title Adjust TimeSpan ticks Fix TLru long ticks policy Apr 22, 2022
@bitfaster bitfaster changed the title Fix TLru long ticks policy Fix TLru long ticks policy on macos Apr 22, 2022
@bitfaster
Copy link
Owner Author

Ran a sanity check to compare before/after speed.

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22000
Intel Xeon W-2133 CPU 3.60GHz, 1 CPU, 12 logical and 6 physical cores
  [Host]             : .NET Framework 4.8 (4.8.4470.0), X64 RyuJIT
  .NET 6.0           : .NET 6.0.4 (6.0.422.16404), X64 RyuJIT
  .NET Framework 4.8 : .NET Framework 4.8 (4.8.4470.0), X64 RyuJIT

LruJustGetOrAdd Before

Method Job Mean StdDev Ratio Code Size Allocated
ConcurrentDictionary .NET 6.0 7.845 ns 0.0765 ns 1.00 1,523 B -
FastConcurrentLru .NET 6.0 9.844 ns 0.0345 ns 1.25 2,185 B -
ConcurrentLru .NET 6.0 13.722 ns 0.1501 ns 1.75 2,211 B -
FastConcurrentTLru .NET 6.0 25.601 ns 0.1341 ns 3.26 2,371 B -
ConcurrentTLru .NET 6.0 30.199 ns 0.4387 ns 3.85 2,446 B -
ClassicLru .NET 6.0 48.579 ns 0.7748 ns 6.19 3,013 B -
RuntimeMemoryCacheGet .NET 6.0 114.579 ns 2.1228 ns 14.61 49 B 32 B
ExtensionsMemoryCacheGet .NET 6.0 60.583 ns 0.6033 ns 7.72 78 B 24 B
ConcurrentDictionary .NET Framework 4.8 14.070 ns 0.1017 ns 1.00 4,207 B -
FastConcurrentLru .NET Framework 4.8 14.590 ns 0.1011 ns 1.04 15,537 B -
ConcurrentLru .NET Framework 4.8 17.422 ns 0.1732 ns 1.24 15,567 B -
FastConcurrentTLru .NET Framework 4.8 46.738 ns 0.2486 ns 3.32 15,882 B -
ConcurrentTLru .NET Framework 4.8 46.749 ns 0.3517 ns 3.32 15,927 B -
ClassicLru .NET Framework 4.8 60.453 ns 0.5656 ns 4.30 6,913 B -
RuntimeMemoryCacheGet .NET Framework 4.8 281.019 ns 1.9630 ns 19.96 33 B 32 B
ExtensionsMemoryCacheGet .NET Framework 4.8 112.906 ns 2.0002 ns 8.02 82 B 24 B

LruJustGetOrAdd After

Method Job Mean StdDev Ratio Code Size Allocated
ConcurrentDictionary .NET 6.0 7.813 ns 0.1015 ns 1.00 1,523 B -
FastConcurrentLru .NET 6.0 10.017 ns 0.1519 ns 1.28 2,185 B -
ConcurrentLru .NET 6.0 13.663 ns 0.0986 ns 1.75 2,211 B -
FastConcurrentTLru .NET 6.0 25.693 ns 0.2367 ns 3.29 2,371 B -
ConcurrentTLru .NET 6.0 30.648 ns 0.7289 ns 3.95 2,446 B -
ClassicLru .NET 6.0 48.787 ns 0.4094 ns 6.25 3,013 B -
RuntimeMemoryCacheGet .NET 6.0 113.700 ns 1.9712 ns 14.55 49 B 32 B
ExtensionsMemoryCacheGet .NET 6.0 57.627 ns 1.6667 ns 7.50 78 B 24 B
ConcurrentDictionary .NET Framework 4.8 13.939 ns 0.0990 ns 1.00 4,207 B -
FastConcurrentLru .NET Framework 4.8 14.711 ns 0.1082 ns 1.06 15,537 B -
ConcurrentLru .NET Framework 4.8 17.636 ns 0.3076 ns 1.27 15,567 B -
FastConcurrentTLru .NET Framework 4.8 44.393 ns 0.2909 ns 3.18 15,882 B -
ConcurrentTLru .NET Framework 4.8 46.624 ns 0.3181 ns 3.34 15,927 B -
ClassicLru .NET Framework 4.8 60.383 ns 0.7938 ns 4.33 6,913 B -
RuntimeMemoryCacheGet .NET Framework 4.8 279.183 ns 2.2605 ns 20.03 33 B 32 B
ExtensionsMemoryCacheGet .NET Framework 4.8 112.639 ns 0.9134 ns 8.08 82 B 24 B

@bitfaster bitfaster merged commit 768fd7f into main Apr 23, 2022
@bitfaster bitfaster deleted the users/alexpeck/macts branch May 18, 2022 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FastConcurrentTLru's Constructor timetolive is not precise on liunx mac platform

2 participants