Closed polushinmk closed 7 years ago
I'll have to look into this on the weekend - I'm not quite sure where we actually could get rid off aync-Statements... If there are any that won't be needed, I'm not against removing those.
However, with these kind of libraries the Web-Requests will always be the bottleneck, so I don't think wie should overthink this.
Could you give me an example of what should be changed and how?
Now:
public async Task<IEnumerable<Comment>> GetCommentsForPost(string PostID, bool embed = false, bool useAuth = false)
{
return await _httpHelper.GetRequest<IEnumerable<Comment>>($"{_defaultPath}{_methodPath}?post={PostID}", embed, useAuth);
}
Then
public Task<IEnumerable<Comment>> GetCommentsForPost(string PostID, bool embed = false, bool useAuth = false)
{
return _httpHelper.GetRequest<IEnumerable<Comment>>($"{_defaultPath}{_methodPath}?post={PostID}", embed, useAuth);
}
List of methods:
AsyncFixer01 The method 'GetCommentsForPost' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Comments.cs 39
AsyncFixer01 The method 'Delete' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Comments.cs 50
AsyncFixer01 The method 'Delete' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\CRUDOperation.cs 71
AsyncFixer01 The method 'GetByID' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\CRUDOperation.cs 104
AsyncFixer01 The method 'Query' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\CRUDOperation.cs 115
AsyncFixer01 The method 'Delete' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\CustomRequest.cs 44
AsyncFixer01 The method 'Delete' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Media.cs 58
AsyncFixer01 The method 'GetByID' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Media.cs 91
AsyncFixer01 The method 'Query' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Media.cs 102
AsyncFixer01 The method 'GetPagesByAuthor' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Pages.cs 38
AsyncFixer01 The method 'GetPagesBySearch' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Pages.cs 52
AsyncFixer01 The method 'Delete' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Pages.cs 65
AsyncFixer01 The method 'Delete' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\PostRevisions.cs 40
AsyncFixer01 The method 'GetAll' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\PostRevisions.cs 50
AsyncFixer01 The method 'GetByID' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\PostRevisions.cs 61
AsyncFixer01 The method 'GetStickyPosts' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Posts.cs 37
AsyncFixer01 The method 'GetPostsByCategory' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Posts.cs 51
AsyncFixer01 The method 'GetPostsByTag' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Posts.cs 65
AsyncFixer01 The method 'GetPostsByAuthor' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Posts.cs 79
AsyncFixer01 The method 'GetPostsBySearch' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Posts.cs 93
AsyncFixer01 The method 'Delete' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Posts.cs 106
AsyncFixer01 The method 'GetByID' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\PostStatuses.cs 54
AsyncFixer01 The method 'GetByID' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\PostTypes.cs 54
AsyncFixer01 The method 'GetByID' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Taxonomies.cs 54
AsyncFixer01 The method 'GetByID' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Users.cs 76
AsyncFixer01 The method 'Query' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Users.cs 87
AsyncFixer01 The method 'GetCurrentUser' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Users.cs 109
AsyncFixer01 The method 'Delete' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Users.cs 120
AsyncFixer01 The method 'Delete' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\Client\Users.cs 131
AsyncFixer01 The method 'GetSettings' do not need to use async/await. WordPressPCL C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCL\WordPressClient.cs 133
AsyncFixer01 The method 'CreateRandomUser' do not need to use async/await. WordPressPCLTests C:\Users\polushin_m_k\Source\Repos\WordPressPCL\WordPressPCLTests\User_Tests.cs 152
Ah, so you would just remove the async & await parts, but this would not change the way the public methods would be called, right? Then we might as well just remove them. :-)
All right! :)
Hi! Some time ago I found on the Internet a link to the plug-in for Visual Studio Async Fixer https://visualstudiogallery.msdn.microsoft.com/03448836-db42-46b3-a5c7-5fc5d36a8308_blank. This plugin analyzes the use of async / await in the code and suggests correcting its incorrect use. At us, according to a plug-in, about 30 incorrect calls async await (AsyncFixer01) which are not necessary, but thus it is generated overhead code.
I decided to run tests using BenchmarkDotNet. The Categories.Query () method was called 25 times with parameters of 100 categories per page The results in the tables below: Using Async / await
Without using async / await
That is, there is a gain in performance, but it is very small. In a real application, the benefit is likely to be quite insensitive, but overall, it cleans up the code a little. What do you think, can be applied recommendations?