Skip to content

Instantly share code, notes, and snippets.

@berfarah
Created October 1, 2018 21:31
Show Gist options
  • Save berfarah/63072d92cd212831ed4cbea8b5f47111 to your computer and use it in GitHub Desktop.
Save berfarah/63072d92cd212831ed4cbea8b5f47111 to your computer and use it in GitHub Desktop.
Iterative Optimization on Hot Paths: Optimization 2: Cutting out the middleman
// goodbye reflect.New in Scanner.Scan
func (s *Scanner) Scan(src interface{}) error {
- s.value = reflect.New(s.Type)
+ // Clear out the value after a scan so we aren't holding onto references.
+ defer func() { s.value = reflect.Value{} }()
// ...
}
// and hello Scanner.Target
+func (s *Scanner) Target(value reflect.Value) {
+ s.value = value
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment