Files icon indicating copy to clipboard operation
Files copied to clipboard

Avoid unnecessary async state machine generation

Open hez2010 opened this issue 2 years ago • 2 comments

We have plenty of code like below:

async IAsyncOperation<T> Foo()
{
    return await AsyncInfo.Run(async () => 
    {
        // no await in the body at all
        return foo;
    });
}

which doesn't actually await anything in an async method. Instead, we should rewrite them to

IAsyncOperation<T> Foo()
{
    return Task.FromResult(foo).AsAsyncOperation();
}

This can avoid unnecessary async state machine be generated to reduce GC pressure.

hez2010 avatar Aug 31 '22 14:08 hez2010

Linking it the performance issues maybe? Anyone taking up that issue may want to dive deeper into optimization.

QuaintMako avatar Aug 31 '22 17:08 QuaintMako

Linking it the performance issues maybe? Anyone taking up that issue may want to dive deeper into optimization.

Good idea

yaira2 avatar Sep 09 '22 17:09 yaira2

I believe there is no longer any return await AsyncInfo.Run methods inside the codebase.

Does this issue also concerns any return AsyncInfo.Run that does not have any await in its instructions?

QuaintMako avatar Nov 13 '22 19:11 QuaintMako

There are still stuff which could be changed in the codebase related to this, can this issue be reopened again?

itsWindows11 avatar Apr 07 '23 15:04 itsWindows11

Can I assume this issue has been resolved?

hez2010 avatar May 09 '23 02:05 hez2010

It should be fully resolved after merging the PR, no problem.

itsWindows11 avatar May 09 '23 10:05 itsWindows11