-
Notifications
You must be signed in to change notification settings - Fork 420
Avoid closures due to implementations in local functions #906
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
Comments
Thanks for bringing this up and shame about the closure because it means reverting all of #290. The local functions really made things pleasant (for all the reasons listed in #290), but I agree that inducing a closure is not worth th 8000 e cost. In fact, if the local function is going to be static, then it might as well be a private method again. |
@atifaziz the function being local has other benefits which are significant, such as being scoped only to that function instead of being callable by the entire class. I don't think you should make them @viceroypenguin do you mind if I ask a related question here? Would this also apply to an public Task DoStuffAsync(string argument, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(argument);
return DoStuffAsync();
async Task DoStuffAsync()
{
await SomethingElseAsync(cancellationToken);
}
} Would it have similar benefits here to make the local function |
Currently, most operators are implemented as such:
A better implementation would be the following:
With the current implementation, the host method must create a closure class before even doing guard statements, copy parameters, and then call a method on that closure class. This means that there are two closure classes: one for the parameters, and one for the enumerator.
Switching to passing the parameters into the iterator method means that only one closure class has to be created, the one for the enumerator; the parameters will be held by that class. This should simplify and improve the IL, the JIT, and the output JIT-ted code.
The text was updated successfully, but these errors were encountered: