@@ -14,7 +14,8 @@ import (
1414 "time"
1515)
1616
17- const defaultBufSize = 4096
17+ const minBufSize = 4096
18+ const defaultBufSize = 16 * 1024
1819
1920// A buffer which is used for both reading and writing.
2021// This is possible since communication on each connection is synchronous.
@@ -42,7 +43,7 @@ func newBuffer(nc net.Conn) buffer {
4243// This is required by Rows.Close().
4344// See https://github.com/golang/go/commit/651ddbdb5056ded455f47f9c494c67b389622a47
4445func (b * buffer ) discard () {
45- if len (b .buf )- b .idx >= defaultBufSize {
46+ if len (b .buf )- b .idx >= minBufSize {
4647 b .buf = b .buf [b .idx :]
4748 b .idx = 0
4849 return
@@ -68,11 +69,9 @@ func (b *buffer) fill(need int) error {
6869 }
6970
7071 // grow buffer if necessary
71- // TODO: let the buffer shrink again at some point
72- // Maybe keep the org buf slice and swap back?
7372 if need > len (b .buf ) {
7473 // Round up to the next multiple of the default size
75- newBuf := make ([]byte , ((need / defaultBufSize )+ 1 )* defaultBufSize )
74+ newBuf := make ([]byte , ((need / minBufSize )+ 1 )* minBufSize )
7675 copy (newBuf , b .buf )
7776 b .buf = newBuf
7877 }
@@ -150,7 +149,7 @@ func (b *buffer) takeBuffer(length int) ([]byte, error) {
150149}
151150
152151// takeSmallBuffer is shortcut which can be used if length is
153- // known to be smaller than defaultBufSize .
152+ // known to be smaller than minBufSize .
154153// Only one buffer (total) can be used at a time.
155154func (b * buffer ) takeSmallBuffer (length int ) ([]byte , error ) {
156155 if b .length > 0 {
0 commit comments