Skip to content
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

Async/await: slow in certain combinations #60444

Open
stefanspringer1 opened this issue Aug 8, 2022 · 1 comment
Open

Async/await: slow in certain combinations #60444

stefanspringer1 opened this issue Aug 8, 2022 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. performance

Comments

@stefanspringer1
Copy link

Describe the bug
Without suspension happening, asynchronous calls should be about as fast as synchronous calls. But this is not always the case.

Steps To Reproduce
Steps to reproduce the behavior:

  1. Run the Swift package https://github.com/stefanspringer1/AsyncBenchmark.

Expected behavior
Without suspension happening, asynchronous calls should be about as fast as synchronous calls.

What happens instead
But in certain circumstances, more precisely for the last three runs in the example, the factor is much higher, up to more than 6000. (In debug mode, only the last number is much higher than 1, it is 22).

Profile data
Attached:
profile.trace.zip

Program output (release):


--------------------------

100000 iterations
Evaluating: Execution...
Time for Execution: 0.0001037 seconds
Evaluating: AsyncExecution...
Time for AsyncExecution: 0.0001041 seconds
100000 iterations done
factor: 1.0040209
difference: 0.0000004

--------------------------

10000 iterations
Evaluating: Execution...
Time for Execution: 0.0000105 seconds
Evaluating: AsyncExecution...
Time for AsyncExecution: 0.0000105 seconds
10000 iterations done
factor: 0.9960952
difference: -0.0000000

--------------------------

1000 iterations
Evaluating: Execution...
Time for Execution: 0.0000011 seconds
Evaluating: AsyncExecution...
Time for AsyncExecution: 0.0000010 seconds
1000 iterations done
factor: 0.9603321
difference: -0.0000000

--------------------------

100 iterations
Evaluating: Execution...
Time for Execution: 0.0000001 seconds
Evaluating: AsyncExecution...
Time for AsyncExecution: 0.0000001 seconds
100 iterations done
factor: 0.6640000
difference: -0.0000000

--- directly in main 1 ---

100000 iterations
Evaluating: Execution...
Time for Execution: 0.0000516 seconds
Evaluating: AsyncExecution...
Time for AsyncExecution: 0.0119533 seconds
100000 iterations done
factor: 231.5407651
difference: 0.0119017

===== NON-ASYNC WORK =====


--------------------------

100000 iterations
Evaluating: Execution...
Time for Execution: 0.0000838 seconds
Evaluating: AsyncExecution...
Time for AsyncExecution: 0.0035407 seconds
100000 iterations done
factor: 42.2342486
difference: 0.0034568

--- directly in main 2 ---

100000 iterations
Evaluating: Execution...
Time for Execution: 0.0000419 seconds
Evaluating: AsyncExecution...
Time for AsyncExecution: 0.4371535 seconds
100000 iterations done
factor: 10429.0254312
difference: 0.4371115
Program ended with exit code: 0

Environment (please fill out the following information)

  • OS: macOS 12.5
  • Xcode Version/Tag/Branch: 13.4.1
  • Swift: 5.6.1

Additional context
Add any other context about the problem here.

@stefanspringer1 stefanspringer1 added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Aug 8, 2022
@stefanspringer1
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. performance
Projects
None yet
Development

No branches or pull requests

2 participants