Skip to content

Conversation

ReverseTM
Copy link
Collaborator

This pull request improves the performance of http writer. By changing the data passed to the template, it was possible to reduce the number of allocations by several times. Also a bug was fixed, because of which the error coming from output.Teardown was not processed.

}

rows = append(rows, rowObj)
// Build a 2D slice of values extracted from dataRows.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are allocating rows slice on each buildRequest call and it defeats much of the benefit of sync.Pool

Consider reusing bodyPayload.Rows 2D slice by getting it from sync.Pool.
Something like that:

// Grab a payload with a ready slice cap.
payload := w.payloadPool.Get().(*bodyPayload)
defer w.payloadPool.Put(payload)

// Reset length to zero, keep cap
payload.Rows = payload.Rows[:0]

// Append each row’s Values slice – no new [][]any heap alloc
for _, dr := range dataRows {
    payload.Rows = append(payload.Rows, dr.Values)
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think you should defer sync.Pool.Put after Get

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants