-
Notifications
You must be signed in to change notification settings - Fork 408
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove fast-path closures from EventBasedLRUCache #2170
Remove fast-path closures from EventBasedLRUCache #2170
Conversation
How does this avoid a closure? The localCacheItem is still outside the delegate, I thought that would have created a closure. |
It doesn't avoid the closure all-up, but it avoids it on the fast path. If you have the code: if (d.TryGetValue(key, out var something))
{
return something;
}
if (whatever)
{
Capture(() => something);
} that will result in the C# compiler generating code along the lines of: <>__DisplayClass_42 display = new();
if (d.TryGetValue(key, out display.something))
{
return display.something;
}
if (whatever)
{
Capture(new Action(display.SomeMethod));
} but if you instead do: if (d.TryGetValue(key, out var something))
{
return something;
}
if (whatever)
{
var localSomething = something;
Capture(() => localSomething);
} the closure moves to the scope in which if (d.TryGetValue(key, out var something))
{
return something;
}
if (whatever)
{
<>__DisplayClass_42 display = new();
display.localSomething = something;
Capture(new Action(display.SomeMethod));
} |
@stephentoub Thanks, that was very interesting. Learn something new every day. |
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.
failing tests
Thanks, I'll take a look. Which tests? I guess CI isn't running any? |
92fbb8a
to
7b05330
Compare
Fixed. I'd accidentally written cacheItem in one place when it should have been newCacheItem. |
No description provided.