save allocations on connect (#1290)

Motivation:

ClientBootstrap.connect was needlessly overallocaing (for a needless
promise and a needless cascade).

Modifications:

Remove the needless allocations.

Result:

Fewer allocations.
This commit is contained in:
Johannes Weiss authored and GitHub committed 2019-12-06 16:55:51 +00:00
1 parent 6761c87d1e
commit eee18dc81f
3 files changed
+6 -9

No files matched your search

+4 -7
View File
@@ -526,20 +526,18 @@ public final class ClientBootstrap {
let channelInitializer = self.channelInitializer ?? { _ in eventLoop.makeSucceededFuture(()) }
let channelOptions = self._channelOptions
let promise = eventLoop.makePromise(of: Channel.self)
let channel: SocketChannel
do {
channel = try SocketChannel(eventLoop: eventLoop as! SelectableEventLoop, protocolFamily: protocolFamily)
} catch let err {
promise.fail(err)
return promise.futureResult
} catch {
return eventLoop.makeFailedFuture(error)
}
@inline(__always)
func setupChannel() -> EventLoopFuture<Channel> {
eventLoop.assertInEventLoop()
// We need to hop to `eventLoop` as the user might have returned a future from a different `EventLoop`.
channelInitializer(channel).hop(to: eventLoop).flatMap {
return channelInitializer(channel).hop(to: eventLoop).flatMap {
channelOptions.applyAllChannelOptions(to: channel)
}.flatMap {
channel.registerAndDoSynchronously(body)
@@ -548,8 +546,7 @@ public final class ClientBootstrap {
}.flatMapError { error in
channel.close0(error: error, mode: .all, promise: nil)
return channel.eventLoop.makeFailedFuture(error)
}.cascade(to: promise)
return promise.futureResult
}
}
if eventLoop.inEventLoop {
+1 -1
View File
@@ -19,7 +19,7 @@ services:
image: swift-nio:16.04-5.1
environment:
- MAX_ALLOCS_ALLOWED_1000_reqs_1_conn=30540
- MAX_ALLOCS_ALLOWED_1_reqs_1000_conn=491050
- MAX_ALLOCS_ALLOWED_1_reqs_1000_conn=490050
- MAX_ALLOCS_ALLOWED_ping_pong_1000_reqs_1_conn=4440
- MAX_ALLOCS_ALLOWED_bytebuffer_lots_of_rw=2100
- MAX_ALLOCS_ALLOWED_future_lots_of_callbacks=75010
+1 -1
View File
@@ -19,7 +19,7 @@ services:
image: swift-nio:18.04-5.0
environment:
- MAX_ALLOCS_ALLOWED_1000_reqs_1_conn=30990
- MAX_ALLOCS_ALLOWED_1_reqs_1000_conn=963050
- MAX_ALLOCS_ALLOWED_1_reqs_1000_conn=962050
- MAX_ALLOCS_ALLOWED_ping_pong_1000_reqs_1_conn=4500
- MAX_ALLOCS_ALLOWED_bytebuffer_lots_of_rw=2100
- MAX_ALLOCS_ALLOWED_future_lots_of_callbacks=75010