Skip to content
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

Improve performance of NIOAsyncChannel #2539

Merged
merged 6 commits into from
Oct 9, 2023

Conversation

FranzBusch
Copy link
Member

Motivation:

There were a couple of easy performance wins in NIOAsyncChannel which cut the allocations in half again. Those performance wins are mostly around the underlying NIOAsyncWriter and NIOAsyncSequenceProducer.

Modifications:

This PR contains a few changes which split up into separate commits to make reviewing easier:

  1. I added a fast path to the NIOAsyncChannelInboundStreamChannelHandlerProducerDelegate which allows it to skip the thread hop when we are already on the correct EventLoop.
  2. I copied over the _TinyArray implementation from swift-certificates to optimise the fast path of having just a single producer suspended in the NIOAsyncWriter.
  3. I implemented the NIOAsyncWriterSinkDelegate customization point for single element writes in the NIOAsyncChannelOutboundWriterHandler. This avoids allocating a Deque for single element writes.
  4. I made sure that we call the single element customization point more often in NIOAsyncWriter and I moved the storage of the suspendedYields to the _TinyArray which optimises for the single producer case.

Result:

Halved the allocations for the NIOAsyncChannel benchmark again.

@FranzBusch
Copy link
Member Author

@swift-server-bot test this please

@FranzBusch FranzBusch enabled auto-merge (squash) October 9, 2023 14:10
@FranzBusch FranzBusch merged commit 94cc73d into apple:main Oct 9, 2023
6 of 8 checks passed
@FranzBusch FranzBusch deleted the fb-async-channel-performance branch October 9, 2023 14:39
@FranzBusch FranzBusch added the semver/patch No public API change. label Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants