Inlining functions is a compiler optimization that replaces the function call site with the body of the callee. This optimization is supported for regular C# functions.
Async functions that support the async-await pattern in C# 5.0 have a special declaration that involves the async
modifier and wrapping return values with Task<>
.
Can async functions be inlined as well?
Example:
Suppose I have these functions:
private async Task<int> CalleeAsync() {
return await SomeOperationAsync();
}
private async Task<int> CallerAsync() {
return await CalleeAsync();
}
Could they be optimized to:
private async Task<int> CallerAsync() {
return await SomeOperationAsync();
}
Extra Credit:
If it is supported, who can decide what's inlined? The compiler? The JIT? me?
If it's not supported, should I worry about this and avoid excessive wrappers I sometimes add for readability?