Skip to content

Test if allocs reduced #3239

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"mallocCountTotal": 82000
"mallocCountTotal" : 108
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"mallocCountTotal" : 164376
}
"mallocCountTotal" : 108
}
20 changes: 10 additions & 10 deletions Sources/NIOCore/AsyncSequences/NIOAsyncWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -561,8 +561,8 @@ extension NIOAsyncWriter {
throw error

case .suspendTask:
return try await withCheckedThrowingContinuation {
(continuation: CheckedContinuation<StateMachine.YieldResult, Error>) in
return try await withUnsafeThrowingContinuation {
(continuation: UnsafeContinuation<StateMachine.YieldResult, Error>) in
let didSuspend = unsafe.withValueAssumingLockIsAcquired {
$0.stateMachine.yield(continuation: continuation, yieldID: yieldID)
return $0.didSuspend
Expand Down Expand Up @@ -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()

Expand All @@ -632,8 +632,8 @@ extension NIOAsyncWriter {
throw error

case .suspendTask:
return try await withCheckedThrowingContinuation {
(continuation: CheckedContinuation<StateMachine.YieldResult, Error>) in
return try await withUnsafeThrowingContinuation {
(continuation: UnsafeContinuation<StateMachine.YieldResult, Error>) in
let didSuspend = unsafe.withValueAssumingLockIsAcquired {
$0.stateMachine.yield(continuation: continuation, yieldID: yieldID)
return $0.didSuspend
Expand Down Expand Up @@ -736,10 +736,10 @@ extension NIOAsyncWriter {
/// The yield's produced sequence of elements.
/// The yield's continuation.
@usableFromInline
var continuation: CheckedContinuation<YieldResult, Error>
var continuation: UnsafeContinuation<YieldResult, Error>

@inlinable
init(yieldID: YieldID, continuation: CheckedContinuation<YieldResult, Error>) {
init(yieldID: YieldID, continuation: UnsafeContinuation<YieldResult, Error>) {
self.yieldID = yieldID
self.continuation = continuation
}
Expand Down Expand Up @@ -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<YieldResult, Error>,
continuation: UnsafeContinuation<YieldResult, Error>,
yieldID: YieldID
) {
switch self._state {
Expand Down Expand Up @@ -1216,7 +1216,7 @@ extension NIOAsyncWriter {
@usableFromInline
enum CancelAction {
/// Indicates that the continuation should be resumed with a `CancellationError`.
case resumeContinuationWithCancellationError(CheckedContinuation<YieldResult, Error>)
case resumeContinuationWithCancellationError(UnsafeContinuation<YieldResult, Error>)
/// Indicates that nothing should be done.
case none
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Element?, any Error>) in
return try await withUnsafeThrowingContinuation {
(continuation: UnsafeContinuation<Element?, any Error>) in
let (action, callDidSuspend) = unsafe.withValueAssumingLockIsAcquired {
let action = $0.stateMachine.next(for: continuation)
let callDidSuspend = $0.didSuspend != nil
Expand Down Expand Up @@ -723,7 +723,7 @@ extension NIOThrowingAsyncSequenceProducer {
case streaming(
backPressureStrategy: Strategy,
buffer: Deque<Element>,
continuation: CheckedContinuation<Element?, Error>?,
continuation: UnsafeContinuation<Element?, Error>?,
hasOutstandingDemand: Bool,
iteratorInitialized: Bool
)
Expand Down Expand Up @@ -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<Element?, Error>,
continuation: UnsafeContinuation<Element?, Error>,
element: Element
)
/// Indicates that the continuation should be resumed and
/// ``NIOThrowingAsyncSequenceProducer/Source/YieldResult/stopProducing`` should be returned.
case resumeContinuationAndReturnStopProducing(
continuation: CheckedContinuation<Element?, Error>,
continuation: UnsafeContinuation<Element?, Error>,
element: Element
)
/// Indicates that the yielded elements have been dropped.
Expand All @@ -931,7 +931,7 @@ extension NIOThrowingAsyncSequenceProducer {
@usableFromInline
init(
shouldProduceMore: Bool,
continuationAndElement: (CheckedContinuation<Element?, Error>, Element)? = nil
continuationAndElement: (UnsafeContinuation<Element?, Error>, Element)? = nil
) {
switch (shouldProduceMore, continuationAndElement) {
case (true, .none):
Expand Down Expand Up @@ -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<Element?, Error>, Failure?)
case resumeContinuationWithFailureAndCallDidTerminate(UnsafeContinuation<Element?, Error>, Failure?)
/// Indicates that nothing should be done.
case none
}
Expand Down Expand Up @@ -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<Element?, Error>)
case resumeContinuationWithCancellationErrorAndCallDidTerminate(UnsafeContinuation<Element?, Error>)
/// Indicates that nothing should be done.
case none
}
Expand Down Expand Up @@ -1273,7 +1273,7 @@ extension NIOThrowingAsyncSequenceProducer {
}

@inlinable
mutating func next(for continuation: CheckedContinuation<Element?, Error>) -> NextForContinuationAction {
mutating func next(for continuation: UnsafeContinuation<Element?, Error>) -> NextForContinuationAction {
switch self._state {
case .initial:
// We are transitioning away from the initial state in `next()`
Expand Down
Loading