mirror of
https://github.com/apple/swift-nio
synced 2026-11-30 05:28:44 +00:00
Motivation:
There are multiple sub-optimal ByteBuffer creation patterns that occur
in the wild. Most often they happen when people don't actually have
access to a `Channel` just want to "convert" a `String` into a
`ByteBuffer`. To do this, they are forced to type
var buffer = ByteBufferAllocator().buffer(capacity: string.utf8.count)
buffer.writeString(string)
Sometimes, they don't get the capacity calculation right or just put a
`0`.
Similar problems happen if NIO users want to cache a ByteBuffer in their
`ChannelHandler`. You will then find this code:
```swift
if self.buffer == nil {
self.buffer = receivedBuffer
} else {
var receivedBuffer = receivedBuffer
self.buffer!.writeBuffer(&receivedBuffer)
}
```
And lastly, sometimes people want to append one `ByteBuffer` to another
without mutating the appendee. That's also cumbersome because we only
support a mutable version of `writeBuffer`.
Modifications:
- add `ByteBuffer` convenience initialisers
- add convenience `writeBuffer` methods to `Optional<ByteBuffer>`
- add `writeBufferImmutable` which doesn't mutate the appendee.
Result:
More convenience.
Co-authored-by: Cory Benfield <lukasa@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
56 lines
1.8 KiB
YAML
56 lines
1.8 KiB
YAML
version: "3"
|
|
|
|
services:
|
|
|
|
runtime-setup:
|
|
image: swift-nio:16.04-5.3
|
|
build:
|
|
args:
|
|
base_image: "swiftlang/swift:nightly-5.3-xenial"
|
|
|
|
unit-tests:
|
|
image: swift-nio:16.04-5.3
|
|
|
|
integration-tests:
|
|
image: swift-nio:16.04-5.3
|
|
|
|
test:
|
|
image: swift-nio:16.04-5.3
|
|
environment:
|
|
- MAX_ALLOCS_ALLOWED_1000_reqs_1_conn=30540
|
|
- MAX_ALLOCS_ALLOWED_1_reqs_1000_conn=480050
|
|
- MAX_ALLOCS_ALLOWED_ping_pong_1000_reqs_1_conn=4440
|
|
- MAX_ALLOCS_ALLOWED_bytebuffer_lots_of_rw=2100
|
|
- MAX_ALLOCS_ALLOWED_future_lots_of_callbacks=75010
|
|
- MAX_ALLOCS_ALLOWED_creating_10000_headers=100
|
|
- MAX_ALLOCS_ALLOWED_scheduling_10000_executions=20150
|
|
- MAX_ALLOCS_ALLOWED_modifying_1000_circular_buffer_elements=50
|
|
- MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_holding_buffer=1010
|
|
- MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_holding_buffer_with_space=1010
|
|
- MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_new_buffer=4010
|
|
- MAX_ALLOCS_ALLOWED_encode_1000_ws_frames_new_buffer_with_space=4010
|
|
- MAX_ALLOCS_ALLOWED_decode_1000_ws_frames=1000
|
|
- MAX_ALLOCS_ALLOWED_modifying_byte_buffer_view=2010
|
|
- MAX_ALLOCS_ALLOWED_schedule_10000_tasks=90050
|
|
- MAX_ALLOCS_ALLOWED_read_10000_chunks_from_file=200500 #5.3 improvement 210050
|
|
- MAX_ALLOCS_ALLOWED_udp_1000_reqs_1_conn=16250
|
|
- MAX_ALLOCS_ALLOWED_udp_1_reqs_1000_conn=226050
|
|
- MAX_ALLOCS_ALLOWED_1000_tcpbootstraps=4100
|
|
- MAX_ALLOCS_ALLOWED_1000_tcpconnections=208100
|
|
- MAX_ALLOCS_ALLOWED_1000_udpbootstraps=4000
|
|
- MAX_ALLOCS_ALLOWED_1000_udpconnections=110050
|
|
- MAX_ALLOCS_ALLOWED_1000_udp_reqs=16050
|
|
- SANITIZER_ARG=--sanitize=thread
|
|
|
|
performance-test:
|
|
image: swift-nio:16.04-5.3
|
|
|
|
shell:
|
|
image: swift-nio:16.04-5.3
|
|
|
|
echo:
|
|
image: swift-nio:16.04-5.3
|
|
|
|
http:
|
|
image: swift-nio:16.04-5.3
|