pubnative / mysqldriver-go

GC optimized MySQL driver
https://godoc.org/github.com/pubnative/mysqldriver-go
MIT License
268 stars 20 forks source link

Avoid string allocations in `NullBool` and `NullInt` methods #11

Closed fhartwig closed 4 years ago

fhartwig commented 4 years ago

Right now NullInt and NullBool get a byte slice from the underlying DB connection buffer, convert it to a string and then parse that string into an int/bool. The conversion from []byte to string requires a memory allocation, which we can avoid by parsing the int/bool directly from the []byte. atoi and parseBool are copied from Go's standard library and modified to work on byte slices instead of strings while preserving the existing behaviour (including errors etc.). Both methods are pretty simple and neither one has had any meaningful changes in the last few years, so I think the maintenance burden of copying them into our code base is pretty small.