Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MB-54131: Geoshape query decode optimization #14

Merged
merged 9 commits into from
Aug 30, 2023
8 changes: 4 additions & 4 deletions s2/buffer_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ func NewGeoBufferPool(maxSize int, minSize int) *GeoBufferPool {
}

func (b *GeoBufferPool) Get(size int) ([]byte) {
Likith101 marked this conversation as resolved.
Show resolved Hide resolved
bufSize := b.maxSize
bufSize := b.minSize

for i := range b.buffers {
if bufSize <= size {
if size <= bufSize || i == len(b.buffers) - 1{
if b.buffers[i] == nil {
b.buffers[i] = make([]byte, bufSize)
}
}

return b.buffers[i]
} else {
bufSize = bufSize / 2
bufSize = bufSize * 2
}
}

Expand Down
14 changes: 9 additions & 5 deletions s2/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,16 @@ func (d *decoder) readUvarint() (x uint64) {
return
}

func (d *decoder) readFloat64Array(size int, buf []byte) ([]byte, int) {
func (d *decoder) readFloat64Array(size int, buf []byte) int {
if d.err != nil || buf == nil {
return nil, 0
return 0
}

_, d.err = io.ReadFull(d.r, buf)

return buf, len(buf)
if size >= len(buf) {
_, d.err = io.ReadFull(d.r, buf)
return len(buf)
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we are using return statement inside "if" block, thus we don't need an else block.

if size >= len(buf) {
  _, d.err = io.ReadFull(d.r, buf)
  return len(buf)
}

_, d.err = io.ReadFull(d.r, buf[0:size])
return size

_, d.err = io.ReadFull(d.r, buf[0:size])
return size
}
}
2 changes: 1 addition & 1 deletion s2/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ func (l *Loop) decode(d *decoder) {

for numBytesNeeded > 0 {
arr := l.BufPool.Get(numBytesNeeded)
arr, numBytesRead := d.readFloat64Array(numBytesNeeded, arr)
numBytesRead := d.readFloat64Array(numBytesNeeded, arr)

if numBytesRead == 0 {
break
Expand Down