- Notifications
You must be signed in to change notification settings - Fork5.2k
More MemoryCache perf improvements#45280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
More MemoryCache perf improvements#45280
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…opagated anyway, +20k RPS for TechEmpower benchmark!
ghost commentedNov 27, 2020
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 OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
| internalboolCheckExpired(DateTimeOffsetnow) | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| internalboolCheckExpired(inDateTimeOffsetnow) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
How much does the ‘in’ help here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I just wanted to be 100% sure that this struct is not being copied on Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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 ofins everywhere unless they're actually meaningful.
| if(_slidingExpiration.HasValue | ||
| &&(now-LastAccessed)>=_slidingExpiration) | ||
| returnSlowPath(now); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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
src/libraries/Microsoft.Extensions.Caching.Memory/src/CacheEntry.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/libraries/Microsoft.Extensions.Caching.Memory/src/CacheEntry.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
eerhardt left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This LGTM. Nice work here@adamsitnik! Looks like a good perf win.
| _notifyCacheEntryCommit(this); | ||
| PropagateOptions(CacheEntryHelper.Current); | ||
| if(CanPropagateOptions()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Always leave a comment about why you're doing what appears to be a redundant check.
| } | ||
| privateboolCheckForExpiredTime(DateTimeOffsetnow) | ||
| privateboolCheckForExpiredTime(inDateTimeOffsetnow) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Same question.

Uh oh!
There was an error while loading.Please reload this page.
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