Skip to content

Commit

Permalink
Improve getBlob performance
Browse files Browse the repository at this point in the history
  • Loading branch information
marco6 committed Jun 3, 2024
1 parent 867753d commit ce368fc
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions internal/protocol/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,18 +322,9 @@ func (m *Message) getString() string {
func (m *Message) getBlob() []byte {
size := m.getUint64()
data := make([]byte, size)
for i := range data {
data[i] = m.getUint8()
}
pad := 0
if (size % messageWordSize) != 0 {
// Account for padding
pad = int(messageWordSize - (size % messageWordSize))
}
// Consume padding
for i := 0; i < pad; i++ {
m.getUint8()
}
b := m.bufferForGet()
defer b.Advance(int(alignUp(size, messageWordSize)))
copy(data, b.Bytes[b.Offset:])
return data
}

Expand Down Expand Up @@ -684,3 +675,8 @@ func (r *Rows) ColumnTypes() ([]string, error) {

return kinds, err
}

// alignUp rounds n up to a multiple of a. a must be a power of 2.
func alignUp(n, a uint64) uint64 {
return (n + a - 1) &^ (a - 1)
}

0 comments on commit ce368fc

Please sign in to comment.