Skip to content

Client API: don't read entire response into a buffer before parsing it #977

Open
@bboreham

Description

@bboreham

The API client functions all follow this pattern, where they make an http call to get back a []byte then decode the JSON:

_, body, warnings, err := h.client.DoGetFallback(ctx, u, q)
if err != nil {
return nil, warnings, err
}
var qres queryResult
return model.Value(qres.v), warnings, json.Unmarshal(body, &qres)

For larger responses, this buffer gets quite expensive (see #976).

I propose that instead we parse JSON from the response body as it comes in.
I can see that this would make handling timeouts more complicated.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions