Skip to content

[Concurrency] Reduce overhead of Task.yield and Task.sleep #37090

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

Merged
merged 2 commits into from
May 10, 2021

Conversation

drexin
Copy link
Contributor

@drexin drexin commented Apr 27, 2021

Instead of creating a new task, we create a simple job that wraps a Builtin.RawUnsafeContinuation and resumes the continuation when it is executed. The job instance is allocated on the task local allocator, meaning we don't malloc anything.

@drexin
Copy link
Contributor Author

drexin commented Apr 27, 2021

@swift-ci smoke test

@drexin drexin requested review from rjmccall and jckarter April 27, 2021 23:54
@drexin drexin force-pushed the wip-improve-yield-sleep branch from 712d674 to 6291698 Compare April 30, 2021 04:21
@drexin
Copy link
Contributor Author

drexin commented Apr 30, 2021

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented Apr 30, 2021

@swift-ci smoke test windows

@drexin
Copy link
Contributor Author

drexin commented Apr 30, 2021

@swift-ci smoke test macos

@drexin
Copy link
Contributor Author

drexin commented Apr 30, 2021

@swift-ci smoke test windows

@drexin drexin force-pushed the wip-improve-yield-sleep branch from 6291698 to 8212492 Compare April 30, 2021 18:52
@drexin
Copy link
Contributor Author

drexin commented Apr 30, 2021

@swift-ci smoke test

@drexin drexin force-pushed the wip-improve-yield-sleep branch from 8212492 to 3f9a58e Compare April 30, 2021 20:51
@drexin
Copy link
Contributor Author

drexin commented Apr 30, 2021

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented May 1, 2021

@swift-ci smoke test macos

1 similar comment
@drexin
Copy link
Contributor Author

drexin commented May 1, 2021

@swift-ci smoke test macos

Instead of creating a new task, we create a simple job that wraps a Builtin.RawUnsafeContinuation and resumes the continuation when it is executed. The job instance is allocated on the task local allocator, meaning we don't malloc anything.
@drexin drexin force-pushed the wip-improve-yield-sleep branch from 3f9a58e to ed00146 Compare May 6, 2021 17:30
@drexin
Copy link
Contributor Author

drexin commented May 6, 2021

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented May 6, 2021

@swift-ci smoke test windows

@drexin
Copy link
Contributor Author

drexin commented May 7, 2021

@swift-ci smoke test macos

continuation);

return job;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return await Builtin.withUnsafeContinuation { (continuation: Builtin.RawUnsafeContinuation) -> Void in
let job = _taskCreateNullaryContinuationJob(priority: priority.rawValue, continuation: continuation)
_enqueueJobGlobal(job)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍

Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks all good to me!

I think you can adjust the @available and merge @drexin, this should be low risk IMO.

Co-authored-by: Konrad `ktoso` Malawski <[email protected]>
@drexin
Copy link
Contributor Author

drexin commented May 9, 2021

@swift-ci smoke test

@drexin
Copy link
Contributor Author

drexin commented May 10, 2021

@swift-ci smoke test windows

1 similar comment
@drexin
Copy link
Contributor Author

drexin commented May 10, 2021

@swift-ci smoke test windows

@drexin
Copy link
Contributor Author

drexin commented May 10, 2021

Windows failure is unrelated.

@drexin drexin merged commit efe6973 into swiftlang:main May 10, 2021
@drexin drexin deleted the wip-improve-yield-sleep branch May 10, 2021 18:51
drexin added a commit to drexin/swift that referenced this pull request May 10, 2021
…#37090)

* [Concurrency] Reduce overhead of Task.yield and Task.sleep

Instead of creating a new task, we create a simple job that wraps a Builtin.RawUnsafeContinuation and resumes the continuation when it is executed. The job instance is allocated on the task local allocator, meaning we don't malloc anything.

* Update stdlib/public/Concurrency/Task.swift

Co-authored-by: Konrad `ktoso` Malawski <[email protected]>

Co-authored-by: Konrad `ktoso` Malawski <[email protected]>
drexin added a commit that referenced this pull request May 11, 2021
…37345)

* [Concurrency] Reduce overhead of Task.yield and Task.sleep

Instead of creating a new task, we create a simple job that wraps a Builtin.RawUnsafeContinuation and resumes the continuation when it is executed. The job instance is allocated on the task local allocator, meaning we don't malloc anything.

* Update stdlib/public/Concurrency/Task.swift

Co-authored-by: Konrad `ktoso` Malawski <[email protected]>

Co-authored-by: Konrad `ktoso` Malawski <[email protected]>

Co-authored-by: Konrad `ktoso` Malawski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants