From bc31ab3d2cda7c087e0208b12b65b13a559df73a Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Sun, 30 Aug 2020 11:42:16 +0300 Subject: [PATCH] storage: add bloom filter to leveldb We're constantly checking for transactions there and most of the time this check is not successful (meaning that the transaction in question is new). Bloom filter easily reduces the need to search over the DB in 99% of these cases and gives some 13% increase in single-node TPS. --- pkg/core/storage/leveldb_store.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/core/storage/leveldb_store.go b/pkg/core/storage/leveldb_store.go index 074b149a8..e3941f0b8 100644 --- a/pkg/core/storage/leveldb_store.go +++ b/pkg/core/storage/leveldb_store.go @@ -2,6 +2,7 @@ package storage import ( "github.com/syndtr/goleveldb/leveldb" + "github.com/syndtr/goleveldb/leveldb/filter" "github.com/syndtr/goleveldb/leveldb/opt" "github.com/syndtr/goleveldb/leveldb/util" ) @@ -21,8 +22,9 @@ type LevelDBStore struct { // NewLevelDBStore returns a new LevelDBStore object that will // initialize the database found at the given path. func NewLevelDBStore(cfg LevelDBOptions) (*LevelDBStore, error) { - var opts *opt.Options // should be exposed via LevelDBOptions if anything needed + var opts = new(opt.Options) // should be exposed via LevelDBOptions if anything needed + opts.Filter = filter.NewBloomFilter(10) db, err := leveldb.OpenFile(cfg.DataDirectoryPath, opts) if err != nil { return nil, err