-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Proposal: Inline async method #43908
Comments
Why? If it's to improve performance, can you show how much this would help you in a realistic scenario? |
For performance.
I got this kind of result. BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.778 (1909/November2018Update/19H2)
Intel Core i9-9900K CPU 3.60GHz (Coffee Lake), 1 CPU, 16 logical and 8 physical cores
[Host] : .NET Framework 4.8 (4.8.4150.0), X64 RyuJIT
.NET 4.8 : .NET Framework 4.8 (4.8.4150.0), X64 RyuJIT
.NET Core 3.1 : .NET Core 3.1.3 (CoreCLR 4.700.20.11803, CoreFX 4.700.20.12001), X64 RyuJIT
Mono 6.8.0 : Mono 6.8.0 (Visual Studio), X64
Each NestedXXX and InlineXXX method doing exactly same things. |
It's unclear what is being asked for here. Can you explain what codegen you would want given an existing code pattern that is written? |
Currently ,if we write this kind of code,these are 5 state machine and 5 tasks created every time we call ShowImageAsync. async ValueTask ShowImageAsync(string url)
{
var blob = DownloadBlobAsync(url);
await RenderImageAsync(blob);
}
async ValueTask<byte[]> DownloadBlobAsync(string url)
{
var connection = await ConnectAsync(url);
return await RequestBlobAsync(connection,url);
}
async ValueTask<Connection> ConnectAsync(string url)
{
ConnectAsync code
}
async ValueTask<byte[]> RequestBlobAsync(Connection connection,string url)
{
RequestBlobAsync code
}
async ValueTask RenderImageAsync(ReadOnlyMemory<byte> blob)
{
RenderImageAsync code
}
We could reduce number of tasks,async state machines by this kind of code generation. async ValueTask ShowImageAsync(string url)
{
var connection = await ConnectAsync code;
var blob = await RequestBlobAsync code;
await RenderImageAsync code;
}
async ValueTask<byte[]> DownloadBlobAsync(string url)
{
var connection = await ConnectAsync code;
return await RequestBlobAsync code;
}
async ValueTask<Connection> ConnectAsync(string url)
{
ConnectAsync code
}
async ValueTask<byte[]> RequestBlobAsync(Connection connection,string url)
{
RequestBlobAsync code
}
async ValueTask RenderImageAsync(ReadOnlyMemory<byte> blob)
{
RenderImageAsync code
} With this code generation, only one state machine and task are created every time we call ShowImageAsync. |
I don't see how that would be ok. it would be inlining all the code (transitively) of all async methods called. That would greatly increase the side of htese methods. |
Similar to #15491 |
You mean the size of these methods? |
Instead of inlining the whole code, can't we just pass the state machine instance to the nested method, so it could modify the state on an existing state machine. meaning: we still have method boundaries but all of them operate on a single state machine. |
Duplicate of #22052 |
cc @genlu |
@RamType-0 we are interested in providing an "inline method" feature more broadly. This issue captures one possible use case, but there are many different teams that could benefit from having this available in different ways. I believe we are starting fairly conservatively with the implementation approach, but would be interested in expanding coverage to new scenarios as they are identified with use of the feature. |
@jinujoseph @sharwell How is this a duplicate? #22052 is about a refactoring (i.e. something that changes the C# code in the editor), while, as I understand it, this issue is about a compiler feature (i.e. something that keeps the C# code intact, but changes the generated IL). Since the two have completely different goals (one is all about removing abstraction, the other is about maintaining it), I don't see how one could be a duplicate of the other. |
yeah, this is asking for a compiler optimization I do not think this should be tracked as part of #22052 |
Duplicate of #15491 |
that is the correct dupe :) |
Currently,each async method creates one state machine.
I wanna combine state machine with nested async method invocation.
It works like F# inline methods, assembly internal only.
The text was updated successfully, but these errors were encountered: