apple / swift-nio-http2

HTTP/2 support for SwiftNIO
https://swiftpackageindex.com/apple/swift-nio-http2/main/documentation/niohttp2
Apache License 2.0
465 stars 82 forks source link

Avoid allocation in outbound frame buffer #385

Closed glbrntt closed 1 year ago

glbrntt commented 1 year ago

Motivation:

CiruclarBuffer always allocates on init as it never has a zero capacity. It is implemented in such a way that changing this is not trivial. The compound outbound buffer creates a marked circular buffer unconditionally on each call but only uses it if there are streams to drop.

Modifications:

Add a static empty marked circular buffer to the compound outbound buffer and rely on CoW semantics to avoid the allocation for each call in cases where there are no frames to drop.

Result:

Fewer allocations.