@@ -14,7 +14,8 @@ import (
14
14
"time"
15
15
)
16
16
17
- const defaultBufSize = 4096
17
+ const minBufSize = 4096
18
+ const defaultBufSize = 16 * 1024
18
19
19
20
// A buffer which is used for both reading and writing.
20
21
// This is possible since communication on each connection is synchronous.
@@ -42,7 +43,7 @@ func newBuffer(nc net.Conn) buffer {
42
43
// This is required by Rows.Close().
43
44
// See https://github.com/golang/go/commit/651ddbdb5056ded455f47f9c494c67b389622a47
44
45
func (b * buffer ) discard () {
45
- if len (b .buf )- b .idx >= defaultBufSize {
46
+ if len (b .buf )- b .idx >= minBufSize {
46
47
b .buf = b .buf [b .idx :]
47
48
b .idx = 0
48
49
return
@@ -68,11 +69,9 @@ func (b *buffer) fill(need int) error {
68
69
}
69
70
70
71
// grow buffer if necessary
71
- // TODO: let the buffer shrink again at some point
72
- // Maybe keep the org buf slice and swap back?
73
72
if need > len (b .buf ) {
74
73
// 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 )
76
75
copy (newBuf , b .buf )
77
76
b .buf = newBuf
78
77
}
@@ -150,7 +149,7 @@ func (b *buffer) takeBuffer(length int) ([]byte, error) {
150
149
}
151
150
152
151
// takeSmallBuffer is shortcut which can be used if length is
153
- // known to be smaller than defaultBufSize .
152
+ // known to be smaller than minBufSize .
154
153
// Only one buffer (total) can be used at a time.
155
154
func (b * buffer ) takeSmallBuffer (length int ) ([]byte , error ) {
156
155
if b .length > 0 {
0 commit comments