Skip to content

Instantly share code, notes, and snippets.

@berfarah
Created October 1, 2018 21:34
Show Gist options
  • Save berfarah/b0aa1b5682d98c782bfed7cfe0a75b46 to your computer and use it in GitHub Desktop.
Save berfarah/b0aa1b5682d98c782bfed7cfe0a75b46 to your computer and use it in GitHub Desktop.
Iterative Optimization on Hot Paths: Optimization 3: Re-use of allocations
func parseQueryRow(table *Table, rows *sql.Rows) (interface{}, error) {
// ...
- values := make([]interface{}, len(table.Columns))
+ values := table.Scanners.Get().([]interface{})
+ defer table.Scanners.Put(values)
for i, column := range table.Columns {
- scanner := column.Descriptor.Scanner()
- scanner.Target(field)
- values[i] = scanner
+ values[i].(*fields.Scanner).Target(field)
}
if err := scanner.Scan(values...); err != nil {
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment