diff --git a/Benchmarks/Thresholds/nightly-main/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json b/Benchmarks/Thresholds/nightly-main/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json index c4f80c1f32..c6a93680d0 100644 --- a/Benchmarks/Thresholds/nightly-main/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json +++ b/Benchmarks/Thresholds/nightly-main/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal": 82000 + "mallocCountTotal" : 108 } diff --git a/Benchmarks/Thresholds/nightly-next/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json b/Benchmarks/Thresholds/nightly-next/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json index 390ed2415a..c6a93680d0 100644 --- a/Benchmarks/Thresholds/nightly-next/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json +++ b/Benchmarks/Thresholds/nightly-next/NIOPosixBenchmarks.TCPEchoAsyncChannel.p90.json @@ -1,3 +1,3 @@ { - "mallocCountTotal" : 164376 -} \ No newline at end of file + "mallocCountTotal" : 108 +} diff --git a/Sources/NIOCore/AsyncSequences/NIOAsyncWriter.swift b/Sources/NIOCore/AsyncSequences/NIOAsyncWriter.swift index f232d518f9..3bbe302680 100644 --- a/Sources/NIOCore/AsyncSequences/NIOAsyncWriter.swift +++ b/Sources/NIOCore/AsyncSequences/NIOAsyncWriter.swift @@ -540,7 +540,7 @@ extension NIOAsyncWriter { let yieldID = yieldID ?? self._yieldIDGenerator.generateUniqueYieldID() return try await withTaskCancellationHandler { - // We are manually locking here to hold the lock across the withCheckedContinuation call + // We are manually locking here to hold the lock across the withUnsafeContinuation call let unsafe = self._state.unsafe unsafe.lock() @@ -561,8 +561,8 @@ extension NIOAsyncWriter { throw error case .suspendTask: - return try await withCheckedThrowingContinuation { - (continuation: CheckedContinuation) in + return try await withUnsafeThrowingContinuation { + (continuation: UnsafeContinuation) in let didSuspend = unsafe.withValueAssumingLockIsAcquired { $0.stateMachine.yield(continuation: continuation, yieldID: yieldID) return $0.didSuspend @@ -611,7 +611,7 @@ extension NIOAsyncWriter { let yieldID = yieldID ?? self._yieldIDGenerator.generateUniqueYieldID() return try await withTaskCancellationHandler { - // We are manually locking here to hold the lock across the withCheckedContinuation call + // We are manually locking here to hold the lock across the withUnsafeContinuation call let unsafe = self._state.unsafe unsafe.lock() @@ -632,8 +632,8 @@ extension NIOAsyncWriter { throw error case .suspendTask: - return try await withCheckedThrowingContinuation { - (continuation: CheckedContinuation) in + return try await withUnsafeThrowingContinuation { + (continuation: UnsafeContinuation) in let didSuspend = unsafe.withValueAssumingLockIsAcquired { $0.stateMachine.yield(continuation: continuation, yieldID: yieldID) return $0.didSuspend @@ -736,10 +736,10 @@ extension NIOAsyncWriter { /// The yield's produced sequence of elements. /// The yield's continuation. @usableFromInline - var continuation: CheckedContinuation + var continuation: UnsafeContinuation @inlinable - init(yieldID: YieldID, continuation: CheckedContinuation) { + init(yieldID: YieldID, continuation: UnsafeContinuation) { self.yieldID = yieldID self.continuation = continuation } @@ -1143,7 +1143,7 @@ extension NIOAsyncWriter { /// This method is called as a result of the above `yield` method if it decided that the task needs to get suspended. @inlinable internal mutating func yield( - continuation: CheckedContinuation, + continuation: UnsafeContinuation, yieldID: YieldID ) { switch self._state { @@ -1216,7 +1216,7 @@ extension NIOAsyncWriter { @usableFromInline enum CancelAction { /// Indicates that the continuation should be resumed with a `CancellationError`. - case resumeContinuationWithCancellationError(CheckedContinuation) + case resumeContinuationWithCancellationError(UnsafeContinuation) /// Indicates that nothing should be done. case none } diff --git a/Sources/NIOCore/AsyncSequences/NIOThrowingAsyncSequenceProducer.swift b/Sources/NIOCore/AsyncSequences/NIOThrowingAsyncSequenceProducer.swift index b807f6f407..46df3af754 100644 --- a/Sources/NIOCore/AsyncSequences/NIOThrowingAsyncSequenceProducer.swift +++ b/Sources/NIOCore/AsyncSequences/NIOThrowingAsyncSequenceProducer.swift @@ -625,8 +625,8 @@ extension NIOThrowingAsyncSequenceProducer { case .suspendTask: // It is safe to hold the lock across this method // since the closure is guaranteed to be run straight away - return try await withCheckedThrowingContinuation { - (continuation: CheckedContinuation) in + return try await withUnsafeThrowingContinuation { + (continuation: UnsafeContinuation) in let (action, callDidSuspend) = unsafe.withValueAssumingLockIsAcquired { let action = $0.stateMachine.next(for: continuation) let callDidSuspend = $0.didSuspend != nil @@ -723,7 +723,7 @@ extension NIOThrowingAsyncSequenceProducer { case streaming( backPressureStrategy: Strategy, buffer: Deque, - continuation: CheckedContinuation?, + continuation: UnsafeContinuation?, hasOutstandingDemand: Bool, iteratorInitialized: Bool ) @@ -916,13 +916,13 @@ extension NIOThrowingAsyncSequenceProducer { /// Indicates that the continuation should be resumed and /// ``NIOThrowingAsyncSequenceProducer/Source/YieldResult/produceMore`` should be returned. case resumeContinuationAndReturnProduceMore( - continuation: CheckedContinuation, + continuation: UnsafeContinuation, element: Element ) /// Indicates that the continuation should be resumed and /// ``NIOThrowingAsyncSequenceProducer/Source/YieldResult/stopProducing`` should be returned. case resumeContinuationAndReturnStopProducing( - continuation: CheckedContinuation, + continuation: UnsafeContinuation, element: Element ) /// Indicates that the yielded elements have been dropped. @@ -931,7 +931,7 @@ extension NIOThrowingAsyncSequenceProducer { @usableFromInline init( shouldProduceMore: Bool, - continuationAndElement: (CheckedContinuation, Element)? = nil + continuationAndElement: (UnsafeContinuation, Element)? = nil ) { switch (shouldProduceMore, continuationAndElement) { case (true, .none): @@ -1040,7 +1040,7 @@ extension NIOThrowingAsyncSequenceProducer { enum FinishAction { /// Indicates that the continuation should be resumed with `nil` and /// that ``NIOAsyncSequenceProducerDelegate/didTerminate()`` should be called. - case resumeContinuationWithFailureAndCallDidTerminate(CheckedContinuation, Failure?) + case resumeContinuationWithFailureAndCallDidTerminate(UnsafeContinuation, Failure?) /// Indicates that nothing should be done. case none } @@ -1094,7 +1094,7 @@ extension NIOThrowingAsyncSequenceProducer { case callDidTerminate /// Indicates that the continuation should be resumed with a `CancellationError` and /// that ``NIOAsyncSequenceProducerDelegate/didTerminate()`` should be called. - case resumeContinuationWithCancellationErrorAndCallDidTerminate(CheckedContinuation) + case resumeContinuationWithCancellationErrorAndCallDidTerminate(UnsafeContinuation) /// Indicates that nothing should be done. case none } @@ -1273,7 +1273,7 @@ extension NIOThrowingAsyncSequenceProducer { } @inlinable - mutating func next(for continuation: CheckedContinuation) -> NextForContinuationAction { + mutating func next(for continuation: UnsafeContinuation) -> NextForContinuationAction { switch self._state { case .initial: // We are transitioning away from the initial state in `next()`