mirror of
https://github.com/apple/swift-nio
synced 2026-11-25 04:47:49 +00:00
improve inEventLoop checks (#3302)
### Motivation: `inEventLoop` is very much in the performance path of SwiftNIO, especially these days with Concurrency, `NIOLoopBound` and friends. Previously, we relied on `pthread_equal(pthread_self(), myPthread)`, however, this could cause a number of issues. 1. Holding onto a `pthread_t` after `.join` is actually illegal (fixed in #3297) 2. Potential ABA issues when `pthread_t` pointer are re-used for new pthreads 3. Fix would require a lock around `myPthread` which makes things (2x slower, even without contention) ### Modifications: - New type `SelectableEventLoopUniqueID` which can be packed into a `UInt` - Attach them into a C thread local ### Result: - Even faster than the old, incorrect version - old: `measuring: el_in_eventloop_100M: 0.257395375, 0.241049208, 0.243188792, 0.259125916, 0.24843225, 0.229690125, 0.244281541, 0.225078834, 0.236395, 0.233305167` - new: `measuring: el_in_eventloop_100M: 0.175561125, 0.187225625, 0.199269375, 0.19740975, 0.1922695, 0.179850958, 0.177612458, 0.17665125, 0.17897475, 0.18038775` - More correct - Groundwork to make #3297 not make things slower
This commit is contained in:
1 parent
57d65ddf9c
commit
0b65385fad
11 files changed
+211
-12
No files matched your search
@@ -81,7 +81,7 @@ public struct ByteCount: Hashable, Sendable {
|
||||
extension ByteCount {
|
||||
/// A ``ByteCount`` for the maximum amount of bytes that can be written to `ByteBuffer`.
|
||||
internal static var byteBufferCapacity: ByteCount {
|
||||
#if arch(arm) || arch(i386) || arch(arm64_32)
|
||||
#if arch(arm) || arch(i386) || arch(arm64_32) || arch(wasm32)
|
||||
// on 32-bit platforms we can't make use of a whole UInt32.max (as it doesn't fit in an Int)
|
||||
let byteBufferMaxIndex = UInt32(Int.max)
|
||||
#else
|
||||
|
||||
Reference in new issue
Block a user