Improve NIOAsyncChannel performance with UnsafeContinuations#3521
Open
fabianfett wants to merge 6 commits intoapple:mainfrom
Open
Improve NIOAsyncChannel performance with UnsafeContinuations#3521fabianfett wants to merge 6 commits intoapple:mainfrom
fabianfett wants to merge 6 commits intoapple:mainfrom
Conversation
FranzBusch
reviewed
Feb 24, 2026
Member
FranzBusch
left a comment
There was a problem hiding this comment.
LGTM. I want @Lukasa to review this though to ensure he is fine with moving over.
43dec89 to
89f2d04
Compare
glbrntt
reviewed
Feb 25, 2026
Comment on lines
+16
to
+20
| /// A Swift Continuation that behaves like a `CheckedContinuation` in Debug mode | ||
| /// and like a `UnsafeContinuation` in release mode. | ||
| /// | ||
| /// - Note: Only use this for code paths that have proven to be safe for at least one year. | ||
| /// All usages must have a comment that states, why it is safe to use NIOUnsafeContinuation. |
Contributor
There was a problem hiding this comment.
You probably want this on the withNIOUnsafe<Blah> as well
Member
Author
There was a problem hiding this comment.
Happy to copy the comment around, but do we really need it?
Contributor
There was a problem hiding this comment.
IMHO, yes. The with method is the point-of-use. When people are quick-looking at the docs associated with the message they should be presented with this caveat.
Lukasa
reviewed
Feb 25, 2026
| (continuation: CheckedContinuation<StateMachine.YieldResult, Error>) in | ||
| // | ||
| // We switched to using NIOUnsafeContinuation after running with | ||
| // CheckedContinuatuion for more than a year. Now we use NIOUnsafeContinuation |
Contributor
There was a problem hiding this comment.
Normally I'm not that nitpicky about typos but this one got copypasta'd everywhere:
Suggested change
| // CheckedContinuatuion for more than a year. Now we use NIOUnsafeContinuation | |
| // CheckedContinuation for more than a year. Now we use NIOUnsafeContinuation |
Lukasa
approved these changes
Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Let's improve NIOAsyncChannels performance, by using UnsafeContinuations instead of CheckedContinuations.
Motivation:
We want to improve the performance for our async APIs.
Modifications:
NIOUnsafeContinuationthat behaves like a UnsafeContinuation in release mode and like a CheckedContinuation in debug mode.NIOUnsafeContinuationinside theNIOAsyncWriterNIOUnsafeContinuationinside theNIOThrowingAsyncSequenceProducerResult:
Fewer allocations