-
Notifications
You must be signed in to change notification settings - Fork 4
Optimize http writer #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…g template, updated usage.md, updated CHANGELOG, and improve and columns are sorted at the point of use.
} | ||
|
||
rows = append(rows, rowObj) | ||
// Build a 2D slice of values extracted from dataRows. |
There was a problem hiding this comment.
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)
}
There was a problem hiding this comment.
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
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.