Skip to content

Commit

Permalink
Reduce allocations on InlineStreamMultiplexer/createStreamChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcairo committed Jul 12, 2024
1 parent ac2a15c commit d237287
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Sources/NIOHTTP2/HTTP2ChannelHandler+InlineStreamMultiplexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ extension InlineStreamMultiplexer {
self._commonStreamMultiplexer.createStreamChannel(multiplexer: .inline(self), streamStateInitializer)
}

@inlinable
internal func createStreamChannel<Output: Sendable>(promise: EventLoopPromise<Output>?, _ initializer: @escaping NIOChannelInitializerWithOutput<Output>) {
self._commonStreamMultiplexer.createStreamChannel(multiplexer: .inline(self), promise: promise, initializer)
}

@inlinable
internal func createStreamChannel<Output: Sendable>(_ initializer: @escaping NIOChannelInitializerWithOutput<Output>) -> EventLoopFuture<Output> {
self._commonStreamMultiplexer.createStreamChannel(multiplexer: .inline(self), initializer)
Expand Down Expand Up @@ -284,19 +289,23 @@ extension InlineStreamMultiplexer {
// Always create streams channels on the next event loop tick. This avoids re-entrancy
// issues where handlers interposed between the two HTTP/2 handlers could create streams
// in channel active which become activated twice.
return self._eventLoop.flatSubmit {
self._inlineStreamMultiplexer.createStreamChannel(initializer)
let promise: EventLoopPromise<Channel> = self._eventLoop.makePromise()
self._eventLoop.execute {
self._inlineStreamMultiplexer.createStreamChannel(promise: promise, initializer)
}
return promise.futureResult
}

@inlinable
internal func createStreamChannel<Output: Sendable>(_ initializer: @escaping NIOChannelInitializerWithOutput<Output>) -> EventLoopFuture<Output> {
// Always create streams channels on the next event loop tick. This avoids re-entrancy
// issues where handlers interposed between the two HTTP/2 handlers could create streams
// in channel active which become activated twice.
return self._eventLoop.flatSubmit {
self._inlineStreamMultiplexer.createStreamChannel(initializer)
let promise: EventLoopPromise<Output> = self._eventLoop.makePromise()
self._eventLoop.execute {
self._inlineStreamMultiplexer.createStreamChannel(promise: promise, initializer)
}
return promise.futureResult
}

internal func setChannelContinuation(_ streamChannels: any AnyContinuation) {
Expand Down

0 comments on commit d237287

Please sign in to comment.