From 5d8ceb7c786d9c6c06f807ef0416103e3176be69 Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Tue, 9 Dec 2025 10:11:58 -0800 Subject: [PATCH] Make MPSCAsyncChannel `#isolation` methods use nonisolated(nonsending)`. We can perform more aggressive optimizer optimizations with nonisolated(nonsending) than #isolation. So use that instead to get some easy perf wins. --- ...MultiProducerSingleConsumerAsyncChannel+Internal.swift | 4 ++-- .../MultiProducerSingleConsumerAsyncChannel.swift | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Sources/AsyncAlgorithms/MultiProducerSingleConsumerChannel/MultiProducerSingleConsumerAsyncChannel+Internal.swift b/Sources/AsyncAlgorithms/MultiProducerSingleConsumerChannel/MultiProducerSingleConsumerAsyncChannel+Internal.swift index ef2567dd..73f5f9e1 100644 --- a/Sources/AsyncAlgorithms/MultiProducerSingleConsumerChannel/MultiProducerSingleConsumerAsyncChannel+Internal.swift +++ b/Sources/AsyncAlgorithms/MultiProducerSingleConsumerChannel/MultiProducerSingleConsumerAsyncChannel+Internal.swift @@ -391,7 +391,7 @@ extension MultiProducerSingleConsumerAsyncChannel { } @inlinable - func next(isolation: isolated (any Actor)? = #isolation) async throws -> Element? { + nonisolated(nonsending) func next() async throws -> Element? { let action = self._stateMachine.withLock { $0.next() } @@ -431,7 +431,7 @@ extension MultiProducerSingleConsumerAsyncChannel { } @inlinable - func suspendNext(isolation: isolated (any Actor)? = #isolation) async throws -> Element? { + nonisolated(nonsending) func suspendNext() async throws -> Element? { try await withTaskCancellationHandler { try await withUnsafeThrowingContinuation { (continuation: UnsafeContinuation) in let action = self._stateMachine.withLock { diff --git a/Sources/AsyncAlgorithms/MultiProducerSingleConsumerChannel/MultiProducerSingleConsumerAsyncChannel.swift b/Sources/AsyncAlgorithms/MultiProducerSingleConsumerChannel/MultiProducerSingleConsumerAsyncChannel.swift index acc9a72a..a889db8a 100644 --- a/Sources/AsyncAlgorithms/MultiProducerSingleConsumerChannel/MultiProducerSingleConsumerAsyncChannel.swift +++ b/Sources/AsyncAlgorithms/MultiProducerSingleConsumerChannel/MultiProducerSingleConsumerAsyncChannel.swift @@ -201,9 +201,7 @@ public struct MultiProducerSingleConsumerAsyncChannel: /// - Parameter isolation: The callers isolation. /// - Returns: The next buffered element. @inlinable - public mutating func next( - isolation: isolated (any Actor)? = #isolation - ) async throws(Failure) -> Element? { + nonisolated(nonsending) public mutating func next() async throws(Failure) -> Element? { do { return try await self.storage.next() } catch { @@ -710,9 +708,7 @@ extension MultiProducerSingleConsumerAsyncChannel.ChannelAsyncSequence where Ele } @inlinable - mutating func next( - isolation actor: isolated (any Actor)? = #isolation - ) async throws(Failure) -> Element? { + nonisolated(nonsending) mutating func next() async throws(Failure) -> Element? { do { return try await self._backing.storage.next(isolation: actor) } catch {