Asynchronous APIs are slower.

We have created a project that returns the average time spent on a large number of asynchronous tasks in one thread and on multiple threads. These tasks are mostly empty and simply cause context to break in the same thread using Task.Yield () expectation. The goal is to evaluate the performance of the task scheduler.

We compiled the same code with .Net Native and without it. The results that we found out were pretty amazing. With .Net, native code has reduced performance by 200% on the phone and about 25% on the desktop application.

Detailed results (better below):

On a mobile device:

Scheduled 20,000 asynchronous tasks and estimated time. We ran this test 10 times to get the average time taken to complete this task.

Single stream (in seconds):

Managed Code (without .Net compilation)

3.02

.Net Native Compiled Code

9.06

Multiple threads (in seconds):

Managed Code (without .Net compilation)

0.10

.Net Native Compiled Code

0.29

On the desktop:

Scheduled 80,000 asynchronous tasks and estimated time. We ran this test 10 times to get the average time taken to complete this task.

Single stream (in seconds):

Managed Code (without .Net compilation)

9.15

.Net Native Compiled Code

11,394

Multiple threads (in seconds):

Managed Code (without .Net compilation)

0.0937

.Net Native Compiled Code

0.177

Our application uses asynchronous APIs to a large extent and has a noticeable degradation in .Net performance. Own compilation. These figures seem to explain degradation if we did not miss something. Has anyone else encountered a similar problem, if so, is there a workaround?

Code snippet:

 for (int i = 0; i < count; i++)
 {
     Task.Run(() => ProcessTaskDesktop());
 }

 public async void ProcessTaskDesktop()
 {
     await Task.Yield();
     .
     .
     //logic to do iterations and check code end
     .
     .
 }

Download the test code here.

+4

All Articles