From af710d3c65ca82f370980b3a603e8f4943bcd6a2 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Fri, 11 Jul 2025 02:18:52 +0300 Subject: [PATCH] Use emhash hashmap (2x faster) --- .gitmodules | 3 +++ emhash | 1 + src/blockstore/blockstore_heap.cpp | 4 ++-- src/blockstore/blockstore_heap.h | 7 ++++--- 4 files changed, 10 insertions(+), 5 deletions(-) create mode 160000 emhash diff --git a/.gitmodules b/.gitmodules index c6636c20..22ccad4e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "json11"] path = json11 url = ../json11.git +[submodule "emhash"] + path = emhash + url = ../emhash.git diff --git a/emhash b/emhash new file mode 160000 index 00000000..b7ff3147 --- /dev/null +++ b/emhash @@ -0,0 +1 @@ +Subproject commit b7ff3147a5b206d6fccd52cd3d63cdbfc4acf8fd diff --git a/src/blockstore/blockstore_heap.cpp b/src/blockstore/blockstore_heap.cpp index 702a8b63..471309fd 100644 --- a/src/blockstore/blockstore_heap.cpp +++ b/src/blockstore/blockstore_heap.cpp @@ -541,7 +541,7 @@ uint64_t blockstore_heap_t::load_blocks(uint64_t disk_offset, uint64_t size, uin next_lsn = wr->lsn; } } - // btree_map anyway stores std::pair's of 16 bytes size + // maps anyway store std::pair's of 16 bytes size // so we can store block_offset in it too block_index[get_pg_id(obj->inode, obj->stripe)][obj->inode][obj->stripe] = (uint8_t*)obj - buf + disk_offset; entries_loaded += wr_i; @@ -818,7 +818,7 @@ void blockstore_heap_t::reshard(pool_id_t pool, uint32_t pg_count, uint32_t pg_s return; } uint64_t pool_id = (uint64_t)pool; - std::unordered_map>> new_shards; + emhash7::HashMap>> new_shards; auto sh_it = block_index.begin(); while (sh_it != block_index.end()) { diff --git a/src/blockstore/blockstore_heap.h b/src/blockstore/blockstore_heap.h index 705f299c..140734a4 100644 --- a/src/blockstore/blockstore_heap.h +++ b/src/blockstore/blockstore_heap.h @@ -11,7 +11,8 @@ #include #include "../client/object_id.h" -//#include "../../cpp-btree/btree_map.h" +#include "../../emhash/hash_table5.hpp" +#include "../../emhash/hash_table7.hpp" #include "blockstore_disk.h" #include "multilist.h" @@ -137,9 +138,9 @@ class blockstore_heap_t uint32_t target_block_free_space = 800; uint64_t next_lsn = 0; - std::unordered_map pool_shard_settings; + emhash7::HashMap pool_shard_settings; // PG => inode => stripe => block number - std::unordered_map>> block_index; + emhash7::HashMap>> block_index; std::vector block_info; allocator_t *data_alloc = NULL; multilist_index_t *meta_alloc = NULL;