Skip to content

Commit f957937

Browse files
LukasaMordil
authored andcommitted
Avoid creating temporary arrays
Motivation: When we only want the first byte, rather than create temporary intermediate arrays we can just ask NIO to give us the first byte. This avoids unnecessary allocations. Modifications: - Replace `readBytes(length: 1).first` with `readInteger(as: UInt8.self)` Results: 11% performance improvement in load testing due to reduced allocator pressure on the hot path.
1 parent dd08685 commit f957937

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sources/RediStack/RESP/RESPTranslator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ extension RESPTranslator {
123123
/// - Returns: The parsed `RESPValue` or nil.
124124
public func parseBytes(from buffer: inout ByteBuffer) throws -> RESPValue? {
125125
var copy = buffer
126-
127-
guard let token = copy.readBytes(length: 1)?.first else { return nil }
126+
127+
guard let token = copy.readInteger(as: UInt8.self) else { return nil }
128128

129129
let result: RESPValue?
130130
switch token {

0 commit comments

Comments
 (0)