3 ms·
Technically, reflection is used by Go’s database Scanner interface, but it’s not what most people think of when they complain about reflection.
by earthboundkid 5y ago
Technically, reflection is used by Go’s database Scanner interface, but it’s not what most people think of when they complain about reflection.
- benhoyt 5y agoGood point. I had assumed Rows.Scan() would have just used type switches for efficiency -- it looks like it does for common cases (https://github.com/golang/go/blob/d62866ef793872779c9011161e51b9c805fcb73d/src/database/sql/convert.go#L220 https://github.com/golang/go/blob/d62866ef793872779c9011161e...) but then falls back to reflect. I wonder why it doesn't just do all of that with type switches? Maybe there are just too many cases and it ends up slower than reflect for the rest of the cases. Scanner.Scan() is actually just called via a type assertion, though I guess implementations of Scan() might use reflection.