apple / swift-nio-http2

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

Reduce allocs in HTTP2StreamChannel #449

Closed glbrntt closed 2 months ago

glbrntt commented 2 months ago

Motivation:

The HTTP2StreamChannel stores two atomic booleans for whether the channel is active and writable. These are only accessed externally and access is relatively infrequent. Each atomic requires an allocation, instead we can just protect each with a single lock.

Modifications:

Result:

Fewer alloations

Lukasa commented 2 months ago

It would be useful to get an idea of whether there's any significant performance impact to this change. I suspect that for most applications it comes out about neutral, but I'm not sure.

glbrntt commented 2 months ago

It would be useful to get an idea of whether there's any significant performance impact to this change. I suspect that for most applications it comes out about neutral, but I'm not sure.

This will obviously depend on how frequently isActive/isWritable are called. My gut feeling is that most users rarely call these.

A concrete example is AHC which uses it a few times per request (in channel active and when writability changes). I used it to benchmark against httpbin (running locally) and the difference was negligible.

gjcairo commented 2 months ago

You'll need to update the allocations for main too