Skip to content

Commit dd08685

Browse files
committed
Avoid transient ByteBufferView
Motivation: When attempting to locate a single byte, creating a transient ByteBufferView is an excessively heavyweight operation compared to a simple getInteger. In particular, a BBV requires retain/release operations to enforce the CoW invariants, as well as requires jumps through substantial amounts of generic Collection code. While this can be specialized, so can getInteger, and getInteger has much less code in the way to cause costs. Modifications: - Replace temporary view creation with getInteger. Results: 5% performance improvement on raw throughput tests.
1 parent 20848b8 commit dd08685

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Sources/RediStack/RESP/RESPTranslator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ extension RESPTranslator {
216216

217217
// sanity check that the declared content size matches the actual size.
218218
guard
219-
buffer.viewBytes(at: buffer.readerIndex + expectedRemainingMessageSize - 1, length: 1)?.first == .newline
219+
buffer.getInteger(at: buffer.readerIndex + expectedRemainingMessageSize - 1, as: UInt8.self) == .newline
220220
else { throw ParsingError.bulkStringSizeMismatch }
221221

222222
// empty content bulk strings are different from null, and represented as .bulkString(nil)

0 commit comments

Comments
 (0)