More MemoryCache perf improvements#45280
Conversation
…opagated anyway, +20k RPS for TechEmpower benchmark!
|
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue Details
+7.5% (+18k) RPS for TechEmpower benchmark!
|
src/libraries/Microsoft.Extensions.Caching.Memory/src/CacheEntry.cs
Outdated
Show resolved
Hide resolved
|
|
||
| internal bool CheckExpired(DateTimeOffset now) | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| internal bool CheckExpired(in DateTimeOffset now) |
There was a problem hiding this comment.
How much does the ‘in’ help here?
There was a problem hiding this comment.
I just wanted to be 100% sure that this struct is not being copied on Linux.
There was a problem hiding this comment.
I just wanted to be 100% sure that this struct is not being copied on Linux.
Did this one change make any measurable impact? We should not be sprinkling lots of ins everywhere unless they're actually meaningful.
|
|
||
| if (_slidingExpiration.HasValue | ||
| && (now - LastAccessed) >= _slidingExpiration) | ||
| return SlowPath(now); |
There was a problem hiding this comment.
Is the idea here that the above check can get inlined, and then the “SlowPath” code remains a normal method call? Is there a good guidance on when this pattern should be used?
Side nit - is “SlowPath” a good name for this method?
There was a problem hiding this comment.
Is the idea here that the above check can get inlined, and then the “SlowPath” code remains a normal method call?
Yes, exactly.
Is there a good guidance on when this pattern should be used?
I would say that it should be used when the condtion typically returns false and rarely executes the code inside it (like throwing exceptions) and is ofc on a hot path (small helper methods executed frequently)
…private helper methods
…ing cache entries
src/libraries/Microsoft.Extensions.Caching.Memory/src/CacheEntry.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Caching.Memory/src/CacheEntry.cs
Outdated
Show resolved
Hide resolved
eerhardt
left a comment
There was a problem hiding this comment.
This LGTM. Nice work here @adamsitnik! Looks like a good perf win.
cc @Tratcher
| _notifyCacheEntryCommit(this); | ||
| PropagateOptions(CacheEntryHelper.Current); | ||
|
|
||
| if (CanPropagateOptions()) |
There was a problem hiding this comment.
Always leave a comment about why you're doing what appears to be a redundant check.
| } | ||
|
|
||
| private bool CheckForExpiredTime(DateTimeOffset now) | ||
| private bool CheckForExpiredTime(in DateTimeOffset now) |

don't acces expensive CacheEntryHelper.Current if options can't be propagated anyway
CacheEntryHelper.Currentuses expensiveAsyncLocal. Before accessing it, we can just check if the options can be propagated and don't use it at all if not.+7.5% (+18k) RPS for TechEmpower benchmark!
inline the expiration check hot paths