← Open Source & Engineering Work
Linux Foundation / Valkey · valkey-io/valkey28/28 CI Green · Valkey Core (PR #5052)

Avoid preallocating fat querybuf after big-arg steal (#5052)

Sole Author: Patrick Ribbsaeter (@patrickswedish) · Immutable Commit SHA: 42518fbfd71a8426fd8e3f3b0bea8567c3fff162

Networking buffer fix replacing eager multi-megabyte SDS_NOINIT preallocation after zero-copy big-arg extraction in parseMultibulk() with tight buffer sizing, eliminating O(N) memmove stalls.

Avoid preallocating fat querybuf after big-arg steal (#5052)

PR #5052

100% CI GREEN · 28/28

42518fb

Immutable Git SHA

C

Systems

28/28 CI Green

CI & Test Matrix

01 · Engineering problem

The failure mode

After stealing c->querybuf for a big bulk argument (>= 32 KB), parseMultibulk() preallocated a new c->querybuf of size c->bulklen + 2, preventing buffer trimming and causing O(N) memmove stalls on trailing pipelined commands.

02 · Technical response

What changed

  1. 01Replaced fat SDS_NOINIT preallocation with sdsempty() after extracting the big argument and copying trailing pipelined bytes into a compact buffer.
  2. 02Updated tests/unit/querybuf.tcl with memory-bound assertions across pipelined big-arg streams.

03 · Verified outcome

Evidence-backed result

  • ✓Passed 39/39 Valkey CI checks on commit 42518fbfd71a8426fd8e3f3b0bea8567c3fff162.

04 · Cryptographic Git record

Immutable source evidence

CValkeyRESP ProtocolZero-Copy NetworkingMemory Allocation

Independent open-source engineering authored solely by Patrick Ribbsaeter (@patrickswedish). Company and project names identify the public repository context only under nominative fair use. No employment, client, vendor, or partnership relationship is implied unless explicitly stated.