Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add perf hooks for testing substring path. #1976

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ func run(identifier: String) {
}
var buffer = ByteBufferAllocator().buffer(capacity: 7 * 1000)
let foundationData = "A".data(using: .utf8)!
let substring = Substring("A")
@inline(never)
func doWrites(buffer: inout ByteBuffer) {
func doWrites(buffer: inout ByteBuffer, dispatchData: DispatchData, substring: Substring) {
/* these ones are zero allocations */
// buffer.writeBytes(foundationData) // see SR-7542
buffer.writeBytes([0x41])
Expand All @@ -34,6 +35,9 @@ func run(identifier: String) {

/* those down here should be one allocation each (on Linux) */
buffer.writeBytes(dispatchData) // see https://bugs.swift.org/browse/SR-9597

/* these here are one allocation on all platforms */
buffer.writeSubstring(substring)
}
@inline(never)
func doReads(buffer: inout ByteBuffer) {
Expand All @@ -54,7 +58,7 @@ func run(identifier: String) {
precondition("A" == str, "\(str!)")
}
for _ in 0..<1000 {
doWrites(buffer: &buffer)
doWrites(buffer: &buffer, dispatchData: dispatchData, substring: substring)
doReads(buffer: &buffer)
}
return buffer.readableBytes
Expand Down
6 changes: 4 additions & 2 deletions Sources/NIOPerformanceTester/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,9 @@ measureAndPrint(desc: "bytebuffer_lots_of_rw") {
DispatchData(bytes: UnsafeRawBufferPointer(start: UnsafeRawPointer(ptr.baseAddress), count: ptr.count))
}
var buffer = ByteBufferAllocator().buffer(capacity: 7 * 1024 * 1024)
let substring = Substring("A")
@inline(never)
func doWrites(buffer: inout ByteBuffer) {
func doWrites(buffer: inout ByteBuffer, dispatchData: DispatchData, substring: Substring) {
/* all of those should be 0 allocations */

// buffer.writeBytes(foundationData) // see SR-7542
Expand All @@ -339,6 +340,7 @@ measureAndPrint(desc: "bytebuffer_lots_of_rw") {
buffer.writeString("A")
buffer.writeStaticString("A")
buffer.writeInteger(0x41, as: UInt8.self)
buffer.writeSubstring(substring)
}
@inline(never)
func doReads(buffer: inout ByteBuffer) {
Expand All @@ -359,7 +361,7 @@ measureAndPrint(desc: "bytebuffer_lots_of_rw") {
precondition("A" == str, "\(str!)")
}
for _ in 0 ..< 1024*1024 {
doWrites(buffer: &buffer)
doWrites(buffer: &buffer, dispatchData: dispatchData, substring: substring)
doReads(buffer: &buffer)
}
return buffer.readableBytes
Expand Down