Skip to content

Commit 98453d4

Browse files
Append params-tuple values onto the header bytearray in place
The prior ``return bytes(header) + b"".join(values)`` chain made three full-size allocations: a copy of the header, a joined values bytestring, and the final concatenation. The bytearray accumulator collapses these to one growing buffer plus one final ``bytes()`` materialisation, matching the pattern already used by the response-side body encoders. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent d4e8135 commit 98453d4

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/dqlitewire/tuples.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,16 @@ def encode_params_tuple(
176176
padding = pad_to_word(absolute_offset)
177177
header.extend(b"\x00" * padding)
178178

179-
# Concatenate header and values
180-
return bytes(header) + b"".join(values)
179+
# Extend the header bytearray with each value in turn, then
180+
# materialise once. Replaces the prior three-allocation chain
181+
# (``bytes(header) + b"".join(values)`` is one full-size header
182+
# copy, one full-size join allocation, and one final concat) with
183+
# a single growing buffer + one final ``bytes()`` materialisation.
184+
# Matches the bytearray pattern adopted by the response-side
185+
# body encoders.
186+
for value_bytes in values:
187+
header.extend(value_bytes)
188+
return bytes(header)
181189

182190

183191
def decode_params_tuple(

0 commit comments

Comments
 (0)