Skip to content

Commit

Permalink
Revert "go: Define a bytePool for TRichTransport"
Browse files Browse the repository at this point in the history
This reverts commit 344498b.

In our extreme case this actually made things worse. On 30s cpu
profiles, although mallocgc reduced from 27.13s to 26.30s, the byte pool
itself costed 11.9s. Looking at writeByte and readByte, writeByte
increased from 3.69s to 5.89s, and readByte increased from 11.36s to
16.09s.
  • Loading branch information
fishy committed May 1, 2024
1 parent 344498b commit 91d3702
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions lib/go/thrift/rich_transport.go
Expand Up @@ -49,15 +49,9 @@ func (r *RichTransport) RemainingBytes() (num_bytes uint64) {
return r.TTransport.RemainingBytes()
}

var bytePool = newPool(nil, func(b *[1]byte) {
b[0] = 0
})

func readByte(r io.Reader) (c byte, err error) {
v := bytePool.get()
defer bytePool.put(&v)

n, err := r.Read(v[:])
v := [1]byte{0}
n, err := r.Read(v[0:1])
if n > 0 && (err == nil || errors.Is(err, io.EOF)) {
return v[0], nil
}
Expand All @@ -71,10 +65,7 @@ func readByte(r io.Reader) (c byte, err error) {
}

func writeByte(w io.Writer, c byte) error {
v := bytePool.get()
defer bytePool.put(&v)

v[0] = c
_, err := w.Write(v[:])
v := [1]byte{c}
_, err := w.Write(v[0:1])
return err
}

0 comments on commit 91d3702

Please sign in to comment.