swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.32k stars 10.34k forks source link

`UnownedTaskExecutor` should be `Hashable` #73780

Open fabianfett opened 4 months ago

fabianfett commented 4 months ago

Motivation

Swift 6 introduces TaskExecutors thanks to SE-0417.

As part of SE-0417, the withUnsafeCurrentTask API was extended so that users can query the unownedTaskExecutor. This is very useful in performance sensitive applications. As I'm currently building a ConnectionPool, I would love to use the returned UnownedTaskExecutor to lookup connections that are running on the executor that asks for the connection to reduce context switches.

For this it would be optimal if UnownedTaskExecutor not just implemented Equatable but also Hashable. So that I don't need to do a linear search through all potential executors and instead can use a dictionary.

Proposed solution

Add Hashable conformance to UnownedTaskExecutor.

Alternatives considered

No response

Additional information

No response

ktoso commented 4 months ago

Agreed, this should be uncontroversial. When used carefully like you do I can see the utility of that.

ktoso commented 3 months ago

rdar://128452304