Skip to content

Commit 2c42bd6

Browse files
committed
feat: add flat_map for optimize JObject
1 parent 4466864 commit 2c42bd6

File tree

6 files changed

+2094
-2066
lines changed

6 files changed

+2094
-2066
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "third-party/parallel-hashmap"]
2+
path = third-party/parallel-hashmap
3+
url = https://github.com/greg7mdp/parallel-hashmap.git

CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,21 @@ else ()
1919
set(CMAKE_CXX_STANDARD 17)
2020
endif ()
2121

22+
message(STATUS "CMAKE_SYSTEM_PROCESSOR:${CMAKE_SYSTEM_PROCESSOR}")
23+
2224
# Detect the architecture
2325
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|i386|i686)$")
2426
set(ARCH_X86 TRUE)
25-
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|aarch64)$")
27+
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|aarch64|arm64)$")
28+
message(STATUS "By default, arm enables NEON for simd optimization")
2629
set(ARCH_ARM TRUE)
2730
else ()
2831
set(ARCH_UNKNOWN TRUE)
2932
endif ()
3033

3134
# Define options for SIMD instruction sets
3235
option(USE_SIMD "Enable SIMD instructions" ON)
36+
option(USE_FLAG_HASH_MAP "Enable FlatHashMap" ON)
3337

3438
# These options are only relevant if SIMD is enabled and the architecture is x86
3539
if ((NOT USE_AVX2 AND (USE_SIMD AND ARCH_X86)) OR USE_SSE4_2)
@@ -67,6 +71,12 @@ endif ()
6771

6872
add_library(ejson ${PROJECT_SOURCE_DIR}/src/ejson/jobject.cc ${PROJECT_SOURCE_DIR}/src/ejson/parser.cc ${PROJECT_SOURCE_DIR}/src/ejson/base64.cc)
6973

74+
if (USE_FLAG_HASH_MAP)
75+
message(STATUS "Use FlatHashMap")
76+
add_definitions(-DUSE_FLAT_HASH_MAP)
77+
target_include_directories(ejson PUBLIC ${PROJECT_SOURCE_DIR}/third-party/parallel-hashmap)
78+
endif ()
79+
7080
if (USE_SIMD)
7181
message(STATUS "Use SIMD Flags:${SIMD_FLAGS}")
7282
target_compile_options(ejson PRIVATE ${SIMD_FLAGS})

src/ejson/jobject.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
#include <unordered_set>
1616
#include <vector>
1717

18+
#ifdef USE_FLAT_HASH_MAP
19+
20+
#include <parallel_hashmap/phmap.h>
21+
22+
#endif
23+
1824
#include "autogen.h"
1925
#include "noncopyable.h"
2026
#include "third_part.h"
@@ -35,7 +41,11 @@ using bool_t = bool;
3541
using double_t = double;
3642
using str_t = string_view;
3743
using list_t = std::vector<JObject>;
38-
using dict_t = std::unordered_map<str_t, JObject>;
44+
#ifdef USE_FLAT_HASH_MAP
45+
using dict_t = phmap::flat_hash_map<str_t, JObject>;
46+
#else
47+
using dict_t = std::map<str_t, JObject>;
48+
#endif
3949

4050
#define EJSON_TYPE_IS(typea, typeb) std::is_same<typea, typeb>::value
4151

0 commit comments

Comments
 (0)