Skip to content

Commit 2ad0461

Browse files
committed
TsFile C++: batch + SIMD + parallel read/write optimization
Batch decode/encode APIs (PLAIN / TS2DIFF / Gorilla) with single-pass TsBlock decode, AVX2/NEON SIMD paths, a single process-wide worker pool for chunk-level parallel read and column-parallel write, and batched NEON statistics. On-disk format unchanged; interoperable with Java/Python.
1 parent 9e929f0 commit 2ad0461

121 files changed

Lines changed: 12937 additions & 2317 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cpp/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,16 @@ else ()
129129
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
130130
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
131131
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
132-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
132+
# -flto + MinGW gcc + statically-linked antlr4_static produces
133+
# unresolved-reference errors at link time (LTO intermediate objects
134+
# can't see the .a's vtable thunks). -march=native is also a poor
135+
# default for CI binaries shipped to other machines. Keep both on
136+
# Linux/macOS where the optimization actually pays off.
137+
if (MINGW OR WIN32)
138+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
139+
else ()
140+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native -flto")
141+
endif ()
133142
elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
134143
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g")
135144
elseif (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")

cpp/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@
9999
plugin's generate goal throw an NPE.
100100
-->
101101
</options>
102-
<sourcePath />
103-
<targetPath />
102+
<sourcePath/>
103+
<targetPath/>
104104
</configuration>
105105
</execution>
106106
<!-- Compile the test code -->

cpp/src/CMakeLists.txt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ message("cmake using: ENABLE_LZOKAY=${ENABLE_LZOKAY}")
3737
option(ENABLE_ZLIB "Enable Zlib compression" ON)
3838
message("cmake using: ENABLE_ZLIB=${ENABLE_ZLIB}")
3939

40+
# ENABLE_SIMD is defined in the top-level CMakeLists.txt
41+
message("cmake using: ENABLE_SIMD=${ENABLE_SIMD}")
42+
4043
message("Running in src directory")
4144
if (${COV_ENABLED})
4245
add_compile_options(-fprofile-arcs -ftest-coverage)
@@ -89,6 +92,13 @@ if (ENABLE_ANTLR4)
8992
message("Adding ANTLR4 include directory")
9093
endif()
9194

95+
if (ENABLE_SIMD)
96+
add_definitions(-DENABLE_SIMD)
97+
list(APPEND PROJECT_INCLUDE_DIR
98+
${CMAKE_SOURCE_DIR}/third_party/simde-0.8.4-rc3
99+
)
100+
endif()
101+
92102
include_directories(${PROJECT_INCLUDE_DIR})
93103

94104
# Mark every translation unit that is compiled into the tsfile library so that
@@ -144,10 +154,17 @@ add_library(tsfile SHARED)
144154

145155
if (${COV_ENABLED})
146156
message("Enable code cov...")
157+
# Apple clang ships coverage runtime via --coverage; libgcov isn't a
158+
# standalone library on macOS. Use --coverage there.
159+
if (APPLE)
160+
set(COV_LINK_LIB --coverage)
161+
else()
162+
set(COV_LINK_LIB -lgcov)
163+
endif()
147164
if (ENABLE_ANTLR4)
148-
target_link_libraries(tsfile common_obj compress_obj cwrapper_obj file_obj read_obj write_obj parser_obj -lgcov)
165+
target_link_libraries(tsfile common_obj compress_obj cwrapper_obj file_obj read_obj write_obj parser_obj ${COV_LINK_LIB})
149166
else()
150-
target_link_libraries(tsfile common_obj compress_obj cwrapper_obj file_obj read_obj write_obj -lgcov)
167+
target_link_libraries(tsfile common_obj compress_obj cwrapper_obj file_obj read_obj write_obj ${COV_LINK_LIB})
151168
endif()
152169
else()
153170
message("Disable code cov...")
@@ -171,4 +188,4 @@ set_target_properties(tsfile PROPERTIES SOVERSION ${LIBTSFILE_SO_VERSION})
171188
install(TARGETS tsfile
172189
RUNTIME DESTINATION ${LIBRARY_OUTPUT_PATH}
173190
LIBRARY DESTINATION ${LIBRARY_OUTPUT_PATH}
174-
ARCHIVE DESTINATION ${LIBRARY_OUTPUT_PATH})
191+
ARCHIVE DESTINATION ${LIBRARY_OUTPUT_PATH})

cpp/src/common/CMakeLists.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,15 @@ aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} common_SRC_LIST)
2222
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/allocator common_allocator_SRC_LIST)
2323
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/container common_container_SRC_LIST)
2424
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/tsblock common_tsblock_SRC_LIST)
25-
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/mutex common_mutex_SRC_LIST)
2625
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/datatype common_datatype_SRC_LIST)
2726

2827
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
29-
add_library(common_obj OBJECT ${common_SRC_LIST}
28+
add_library(common_obj OBJECT ${common_SRC_LIST}
3029
${common_allocator_SRC_LIST}
3130
${common_container_SRC_LIST}
32-
${common_tsblock_SRC_LIST}
33-
${common_mutex_SRC_LIST}
31+
${common_tsblock_SRC_LIST}
3432
${common_datatype_SRC_LIST})
3533

36-
if (ENABLE_ANTLR4)
37-
target_compile_definitions(common_obj PRIVATE ENABLE_ANTLR4)
38-
endif()
39-
4034
# install header files recursively
4135
file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
4236
copy_to_dir(${HEADERS} "common_obj")

cpp/src/common/allocator/alloc_base.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,35 +82,43 @@ class ModStat {
8282
}
8383
void init();
8484
void destroy();
85-
INLINE void update_alloc(AllocModID mid, int32_t size) {
85+
INLINE void update_alloc(AllocModID mid, int64_t size) {
8686
#ifdef ENABLE_MEM_STAT
8787
ASSERT(mid < __LAST_MOD_ID);
8888
ATOMIC_FAA(get_item(mid), size);
8989
#endif
9090
}
91-
void update_free(AllocModID mid, uint32_t size) {
91+
void update_free(AllocModID mid, uint64_t size) {
9292
#ifdef ENABLE_MEM_STAT
9393
ASSERT(mid < __LAST_MOD_ID);
94-
ATOMIC_FAA(get_item(mid), 0 - size);
94+
ATOMIC_FAA(get_item(mid), -static_cast<int64_t>(size));
9595
#endif
9696
}
9797
void print_stat();
9898

99+
int64_t get_stat(int8_t mid) {
100+
#ifdef ENABLE_MEM_STAT
101+
if (stat_arr_ != NULL && mid < __LAST_MOD_ID)
102+
return ATOMIC_FAA(get_item(mid), 0LL);
103+
#endif
104+
return 0;
105+
}
106+
99107
#ifdef ENABLE_TEST
100-
int32_t TEST_get_stat(int8_t mid) { return ATOMIC_FAA(get_item(mid), 0); }
108+
int64_t TEST_get_stat(int8_t mid) { return ATOMIC_FAA(get_item(mid), 0LL); }
101109
#endif
102110

103111
private:
104-
INLINE int32_t* get_item(int8_t mid) {
105-
return &(stat_arr_[mid * (ITEM_SIZE / sizeof(int32_t))]);
112+
INLINE int64_t* get_item(int8_t mid) {
113+
return &(stat_arr_[mid * (ITEM_SIZE / sizeof(int64_t))]);
106114
}
107115

108116
private:
109117
static const int32_t ITEM_SIZE = CACHE_LINE_SIZE;
110118
static const int32_t ITEM_COUNT = __LAST_MOD_ID;
111-
int32_t* stat_arr_;
119+
int64_t* stat_arr_;
112120

113-
STATIC_ASSERT((ITEM_SIZE % sizeof(int32_t) == 0), ModStat_ITEM_SIZE_ERROR);
121+
STATIC_ASSERT((ITEM_SIZE % sizeof(int64_t) == 0), ModStat_ITEM_SIZE_ERROR);
114122
};
115123

116124
/* base allocator */

0 commit comments

Comments
 (0)