Skip to content

[SR-761] dispatch_async is "not very concurrent" and has a 1s overhead on Linux #751

@drewcrawford

Description

@drewcrawford
Previous ID SR-761
Radar None
Original Reporter @drewcrawford
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Linux x64
swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a

Additional Detail from JIRA
Votes 0
Component/s libdispatch
Labels Bug, Linux
Assignee frankeh (JIRA)
Priority Medium

md5: b2ed8e5cf6e4eaac3f1ede31d47b998f

Issue Description:

The attached program enqueues 10 blocks of work on the default queue. On Darwin, all blocks run in parallel, and the program completes in 5 seconds:

0.0 block 0 enter
0.0 block 7 enter
0.0 block 1 enter
0.0 block 3 enter
0.0 block 2 enter
0.0 block 4 enter
0.0 block 5 enter
0.0 block 6 enter
0.0 block 8 enter
0.0 block 9 enter
5.0 block 1 leave
5.0 block 6 leave
5.0 block 9 leave
5.0 block 5 leave
5.0 block 3 leave
5.0 block 0 leave
5.0 block 8 leave
5.0 block 4 leave
5.0 block 2 leave
5.0 block 7 leave
5.0 finished

On Linux however, the blocks enter the queue staggered 1 at a time, 1 second apart. This doubles the runtime of the program:

0.0 block 1 enter
0.0 block 0 enter
1.0 block 2 enter
2.0 block 3 enter
3.0 block 4 enter
4.0 block 5 enter
5.0 block 1 leave
5.0 block 0 leave
5.0 block 6 enter
5.0 block 7 enter
5.0 block 8 enter
6.0 block 2 leave
6.0 block 9 enter
7.0 block 3 leave
8.0 block 4 leave
9.0 block 5 leave
10.0 block 6 leave
10.0 block 7 leave
10.0 block 8 leave
11.0 block 9 leave
11.0 finished

In addition to that (rather large) performance regression, the fact that dispatch_async and/or the default queue has in practice a constant-time overhead of 1 second on Linux breaks a lot of my Darwin code, which expects a Darwin-like overhead for this call.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions