Skip to content

Avoid allocating new slice for data on every Receive() #16

@jonhoo

Description

@jonhoo

In MCRequest.Receive, a new buffer is allocated for every receive for the body of the request:

buf := make([]byte, klen+elen+bodyLen)

It would be great if this function could instead accept a buffer as an argument so that buffers could be re-used across requests. The code could use cap(buf) to ensure that the buffer is long enough, and buf = buf[:klen+elen+bodyLen] to limit its length. Only if it buf is too small should it allocate its own (and potentially warn the caller that the buffer was not used).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions