Created
October 1, 2018 21:34
-
-
Save berfarah/b0aa1b5682d98c782bfed7cfe0a75b46 to your computer and use it in GitHub Desktop.
Iterative Optimization on Hot Paths: Optimization 3: Re-use of allocations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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