Skip to content

Go: GoBytes+string double-copies FFI string payloads (large GET/MGET RSS) #6751

Description

@superbaddude

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Optimization 🐌Optimization matter such as cleaner code, performance etcUser issue 🚨Issue opened by a usergo 🏃golang wrapper

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions