Skip to content

Commit a73f1a7

Browse files
committed
SwiftQUIC: Reduce CPU overhead in getting inbound stream data delivered to the stream
1 parent 64f492d commit a73f1a7

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

Sources/SwiftNetwork/Protocols/ManyToManyProtocol.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,15 @@ extension ManyToManyApplicationStreamProtocol where Flow: AutomaticUpperStreamPr
13881388
guard let flow = self.flow(for: flowID) else { throw NetworkError.posix(EINVAL) }
13891389
flow.serviceUpperReceiveQueue()
13901390
}
1391+
// Enqueue and delivery the stream data all in one shot
1392+
public func deliverInboundStreamData(
1393+
flow flowID: MultiplexedFlowIdentifier,
1394+
streamData: consuming FrameArray
1395+
) throws(NetworkError) {
1396+
guard var flow = self.flow(for: flowID) else { throw NetworkError.posix(EINVAL) }
1397+
try flow.addToUpperReceiveQueue(streamData)
1398+
flow.serviceUpperReceiveQueue()
1399+
}
13911400
}
13921401

13931402
@_spi(ProtocolProvider)

Sources/SwiftNetwork/QUIC/QUICConnection.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,8 +2374,7 @@ public final class QUICConnection: ManyToManyApplicationStreamProtocol,
23742374
continue
23752375
}
23762376

2377-
try? enqueueInboundStreamData(flow: flowID, streamData: frameArray)
2378-
try? deliverEnqueuedInboundStreamData(flow: flowID)
2377+
try? deliverInboundStreamData(flow: flowID, streamData: frameArray)
23792378

23802379
// When the stream is already in `resetReceived` state,
23812380
// it should be closed when we receive STOP_SENDING, so we
@@ -4317,8 +4316,7 @@ public final class QUICConnection: ManyToManyApplicationStreamProtocol,
43174316
}
43184317
if let frameArray = stream.dequeueReassembledData(connection: self) {
43194318
do {
4320-
try enqueueInboundStreamData(flow: flowID, streamData: frameArray)
4321-
try deliverEnqueuedInboundStreamData(flow: flowID)
4319+
try deliverInboundStreamData(flow: flowID, streamData: frameArray)
43224320
sendFrames()
43234321
} catch {
43244322
log.error("Error sending frames on stream close: \(error)")

Sources/SwiftNetwork/QUIC/QUICStream.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ struct StreamListMembership: OptionSet {
328328
// Also note that a flow identifier can exist in multiple lists at one time.
329329
@available(Network 0.1.0, *)
330330
struct QUICStreamList: ~Copyable {
331-
private var list: [MultiplexedFlowIdentifier] = []
331+
private var list: Deque<MultiplexedFlowIdentifier> = []
332332
private let name: StaticString
333333
private let listType: StreamListMembership
334334

0 commit comments

Comments
 (0)