Skip to content

Commit

Permalink
saved at least not ruining attempts to speed up mdbxgo_get
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Miheev committed Jun 7, 2024
1 parent 2cc4e87 commit 0c8d950
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/erigontech/mdbx-go

go 1.15
go 1.22

require (
github.com/benesch/cgosymbolizer v0.0.0-20190515212042-bec6fe6e597b
Expand Down
9 changes: 8 additions & 1 deletion mdbx/mdbxgo.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#undef _GLIBCXX_DEBUG // disable run-time bound checking, etc
#pragma GCC optimize("Ofast,inline") // Ofast = O3,fast-math,allow-store-data-races,no-protect-parens

#pragma GCC target("bmi,bmi2,lzcnt,popcnt") // bit manipulation
#pragma GCC target("movbe") // byte swap
#pragma GCC target("aes,pclmul,rdrnd") // encryption
#pragma GCC target("avx,avx2,f16c,fma,sse3,ssse3,sse4.1,sse4.2") // SIMD
/* lmdbgo.c
* Helper utilities for github.com/bmatsuo/lmdb-go/lmdb
* */
Expand Down Expand Up @@ -35,7 +42,7 @@ int mdbxgo_del(MDBX_txn *txn, MDBX_dbi dbi, char *kdata, size_t kn, char *vdata,
return mdbx_del(txn, dbi, &key, NULL);
}

int mdbxgo_get(MDBX_txn *txn, MDBX_dbi dbi, char *kdata, size_t kn, MDBX_val *val) {
int mdbxgo_get(const MDBX_txn* restrict txn , MDBX_dbi dbi, char* restrict kdata, const size_t kn, MDBX_val* restrict val) MDBX_CXX17_NOEXCEPT {
MDBX_val key;
MDBXGO_SET_VAL(&key, kn, kdata);
return mdbx_get(txn, dbi, &key, val);
Expand Down
9 changes: 8 additions & 1 deletion mdbx/mdbxgo.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#undef _GLIBCXX_DEBUG // disable run-time bound checking, etc
#pragma GCC optimize("Ofast,inline") // Ofast = O3,fast-math,allow-store-data-races,no-protect-parens

#pragma GCC target("bmi,bmi2,lzcnt,popcnt") // bit manipulation
#pragma GCC target("movbe") // byte swap
#pragma GCC target("aes,pclmul,rdrnd") // encryption
#pragma GCC target("avx,avx2,f16c,fma,sse3,ssse3,sse4.1,sse4.2") // SIMD
/* lmdbgo.h
* Helper utilities for github.com/bmatsuo/lmdb-go/lmdb. These functions have
* no compatibility guarantees and may be modified or deleted without warning.
Expand All @@ -18,7 +25,7 @@
* https://github.com/bmatsuo/lmdb-go/issues/63
* */
int mdbxgo_del(MDBX_txn *txn, MDBX_dbi dbi, char *kdata, size_t kn, char *vdata, size_t vn);
int mdbxgo_get(MDBX_txn *txn, MDBX_dbi dbi, char *kdata, size_t kn, MDBX_val *val);
int mdbxgo_get(const MDBX_txn* restrict txn , MDBX_dbi dbi, char* restrict kdata, const size_t kn, MDBX_val* restrict val) MDBX_CXX17_NOEXCEPT;
int mdbxgo_put1(MDBX_txn *txn, MDBX_dbi dbi, char *kdata, size_t kn, MDBX_val *val, MDBX_put_flags_t flags);
int mdbxgo_put2(MDBX_txn *txn, MDBX_dbi dbi, char *kdata, size_t kn, char *vdata, size_t vn, MDBX_put_flags_t flags);
int mdbxgo_cursor_put1(MDBX_cursor *cur, char *kdata, size_t kn, MDBX_val *val, MDBX_put_flags_t flags);
Expand Down
1 change: 1 addition & 0 deletions mdbx/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ func (txn *Txn) Get(dbi DBI, key []byte) ([]byte, error) {
*txn.val = C.MDBX_val{}
return nil, err
}

b := castToBytes(txn.val)
*txn.val = C.MDBX_val{}
return b, nil
Expand Down
2 changes: 1 addition & 1 deletion mdbx/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ func BenchmarkTxn_Get(b *testing.B) {
if err := env.View(func(txn *Txn) (err error) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := txn.Get(db, k)
_, err = txn.Get(db, k)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion mdbxdist/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ MDBX_BUILD_TIMESTAMP ?=$(shell date +%Y-%m-%dT%H:%M:%S%z)
MDBX_BUILD_CXX ?= YES

# probe and compose common compiler flags with variable expansion trick (seems this work two times per session for GNU Make 3.81)
CFLAGS ?= $(strip $(eval CFLAGS := -std=gnu11 -O2 -g -Wall -Werror -Wextra -Wpedantic -ffunction-sections -fPIC -fvisibility=hidden -pthread -Wno-error=attributes $$(shell for opt in -fno-semantic-interposition -Wno-unused-command-line-argument -Wno-tautological-compare; do [ -z "$$$$($(CC) '-DMDBX_BUILD_FLAGS="probe"' $$$${opt} -c $(SRC_PROBE_C) -o /dev/null >/dev/null 2>&1 || echo failed)" ] && echo "$$$${opt} "; done)$(CFLAGS_EXTRA))$(CFLAGS))
CFLAGS ?= $(strip $(eval CFLAGS := -std=gnu11 -O2 -march=native -g -Wall -Werror -Wextra -Wpedantic -ffunction-sections -fPIC -fvisibility=hidden -pthread -Wno-error=attributes $$(shell for opt in -fno-semantic-interposition -Wno-unused-command-line-argument -Wno-tautological-compare; do [ -z "$$$$($(CC) '-DMDBX_BUILD_FLAGS="probe"' $$$${opt} -c $(SRC_PROBE_C) -o /dev/null >/dev/null 2>&1 || echo failed)" ] && echo "$$$${opt} "; done)$(CFLAGS_EXTRA))$(CFLAGS))

# choosing C++ standard with variable expansion trick (seems this work two times per session for GNU Make 3.81)
CXXSTD ?= $(eval CXXSTD := $$(shell for std in gnu++23 c++23 gnu++2b c++2b gnu++20 c++20 gnu++2a c++2a gnu++17 c++17 gnu++1z c++1z gnu++14 c++14 gnu++1y c++1y gnu+11 c++11 gnu++0x c++0x; do $(CXX) -std=$$$${std} -c $(SRC_PROBE_CXX) -o /dev/null 2>probe4std-$$$${std}.err >/dev/null && echo "-std=$$$${std}" && exit; done))$(CXXSTD)
Expand Down
4 changes: 2 additions & 2 deletions mdbxdist/mdbx.c
Original file line number Diff line number Diff line change
Expand Up @@ -20170,7 +20170,7 @@ static __always_inline int node_read(MDBX_cursor *mc, const MDBX_node *node,
}

int mdbx_get(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key,
MDBX_val *data) {
MDBX_val *data) MDBX_CXX17_NOEXCEPT {
DKBUF_DEBUG;
DEBUG("===> get db %u key [%s]", dbi, DKEY_DEBUG(key));

Expand Down Expand Up @@ -20510,7 +20510,7 @@ static int cursor_prev(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,

/* Set the cursor on a specific data item. */
__hot static struct cursor_set_result
cursor_set(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data, MDBX_cursor_op op) {
cursor_set(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data, MDBX_cursor_op op) MDBX_CXX17_NOEXCEPT {
MDBX_page *mp;
MDBX_node *node = NULL;
DKBUF_DEBUG;
Expand Down
2 changes: 1 addition & 1 deletion mdbxdist/mdbx.h
Original file line number Diff line number Diff line change
Expand Up @@ -4426,7 +4426,7 @@ LIBMDBX_API int mdbx_drop(MDBX_txn *txn, MDBX_dbi dbi, bool del);
* \retval MDBX_NOTFOUND The key was not in the database.
* \retval MDBX_EINVAL An invalid parameter was specified. */
LIBMDBX_API int mdbx_get(const MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key,
MDBX_val *data);
MDBX_val *data) MDBX_CXX17_NOEXCEPT;

/** \brief Get items from a database
* and optionally number of data items for a given key.
Expand Down

0 comments on commit 0c8d950

Please sign in to comment.