Skip to content

Commit

Permalink
replace txn.Get with txn.GetFast realization
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Miheev committed Jun 12, 2024
1 parent 5bfb29d commit 6f9a27c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 58 deletions.
24 changes: 2 additions & 22 deletions mdbx/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,26 +587,6 @@ func (txn *Txn) bytes(val *C.MDBX_val) []byte {
//
// See mdbx_get.
func (txn *Txn) Get(dbi DBI, key []byte) ([]byte, error) {
var k *C.char
if len(key) > 0 {
k = (*C.char)(unsafe.Pointer(&key[0]))
}
ret := C.mdbxgo_get(
txn._txn, C.MDBX_dbi(dbi),
k, C.size_t(len(key)),
txn.val,
)
err := operrno("mdbx_get", ret)
if err != nil {
*txn.val = C.MDBX_val{}
return nil, err
}
b := castToBytes(txn.val)
*txn.val = C.MDBX_val{}
return b, nil
}

func (txn *Txn) GetFast(dbi DBI, key []byte) ([]byte, error) {
var k *C.char
if len(key) > 0 {
k = (*C.char)(unsafe.Pointer(&key[0]))
Expand All @@ -618,11 +598,11 @@ func (txn *Txn) GetFast(dbi DBI, key []byte) ([]byte, error) {
)
err := operrno("mdbx_get", ret)
if err != nil {
txn.valNP = C.MDBX_val{}
txn.valNP.iov_base, txn.valNP.iov_len = nil, 0
return nil, err
}
b := castToBytes(&txn.valNP)
txn.valNP = C.MDBX_val{}
txn.valNP.iov_base, txn.valNP.iov_len = nil, 0
return b, nil
}

Expand Down
36 changes: 0 additions & 36 deletions mdbx/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1299,42 +1299,6 @@ func BenchmarkTxn_Get(b *testing.B) {
}
}

func BenchmarkTxn_GetFast(b *testing.B) {
env, _ := setup(b)

var db DBI
k := make([]byte, 8)
binary.BigEndian.PutUint64(k, uint64(1))

if err := env.Update(func(txn *Txn) (err error) {
db, err = txn.OpenRoot(0)
if err != nil {
return err
}
err = txn.Put(db, k, k, 0)
if err != nil {
return err
}
return nil
}); err != nil {
b.Errorf("dbi: %v", err)
return
}

if err := env.View(func(txn *Txn) (err error) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := txn.GetFast(db, k)
if err != nil {
return err
}
}
return nil
}); err != nil {
b.Errorf("put: %v", err)
}
}

func TestTxnEnvWarmup(t *testing.T) {
env, _ := setup(t)

Expand Down

0 comments on commit 6f9a27c

Please sign in to comment.