Describe the bug
In the Go client, string responses from the FFI layer are converted with:
byteSlice := C.GoBytes(..., len)
return string(byteSlice)
C.GoBytes allocates a Go []byte copy of the C buffer, and string(...) allocates a second copy. For large GET / MGET values this doubles peak Go heap traffic for every payload (binary-safe including interior NULs).
This is independent of the v2.5.0 ResponseArena payload leak (#6740 / #6741). Even with arenas releasing FFI buffers correctly, the Go binding still pays two heap copies per string response.
Expected Behavior
One copy from the FFI char* into a Go string (still preserving length and interior NULs).
Current Behavior
Two allocations / two full payload copies per string response (GoBytes then string).
Reproduction / evidence
Microbenchmark in the linked PR (1 MiB payload):
| path |
allocs/op |
B/op |
GoStringN |
1 |
~1 MiB |
GoBytes + string |
2 |
~2 MiB |
Proposed fix
Use C.GoStringN(ptr, len) in convertCharArrayToString and parseString. GoStringN is length-based and preserves interior NULs (same semantics as the current path).
Related
Describe the bug
In the Go client, string responses from the FFI layer are converted with:
C.GoBytesallocates a Go[]bytecopy of the C buffer, andstring(...)allocates a second copy. For largeGET/MGETvalues this doubles peak Go heap traffic for every payload (binary-safe including interior NULs).This is independent of the v2.5.0 ResponseArena payload leak (#6740 / #6741). Even with arenas releasing FFI buffers correctly, the Go binding still pays two heap copies per string response.
Expected Behavior
One copy from the FFI
char*into a Gostring(still preserving length and interior NULs).Current Behavior
Two allocations / two full payload copies per string response (
GoBytesthenstring).Reproduction / evidence
Microbenchmark in the linked PR (1 MiB payload):
GoStringNGoBytes+stringProposed fix
Use
C.GoStringN(ptr, len)inconvertCharArrayToStringandparseString.GoStringNis length-based and preserves interior NULs (same semantics as the current path).Related