pingcap/go-ycsb

BufPool is meaningless actually

divanodestiny opened this issue · 0 comments

code

func (db *txnDB) Insert(ctx context.Context, table string, key string, values map[string][]byte) error { // Simulate TiDB data	buf := db.bufPool.Get()	defer db.bufPool.Put(buf)
	rowData, err := db.r.Encode(buf.Bytes(), values)
	// ...
}

pass buf.Bytes() as param and append bytes to it in method Encode will never change the underlaid slice of buf, and you never initial the underlaid slice so that it always nil actually.

you can try the test code below to check

func TestBufPool(t *testing.T) {
	bufPool := util.NewBufPool()
	buf := bufPool.Get()
	defer func() {
		fmt.Println(buf.Cap())
		bufPool.Put(buf)
	}()
	str := string(appendSomething(buf.Bytes()))
	fmt.Println(str)
}

func appendSomething(bs []byte) []byte{
	return append(bs, []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")...)
}