Skip to content

Commit a143e9d

Browse files
jleibsWumpf
andauthored
Improve C++ SDK perf 5x by respecting CMAKE_BUILD_TYPE and enabling mimalloc (#4094)
### What - Resolves: #4093 Arrow was default to a Debug build regardless of what CMAKE_BUILD_TYPE was specified. Baseline: ``` $ time RERUN=on ./build/rerun_vrs_example sample.vrs real 0m15.105s user 0m16.409s sys 0m2.981s ``` `CMAKE_BUILD_TYPE=RelWithDebInfo` ``` $ time RERUN=on ./build/rerun_vrs_example sample.vrs real 0m4.659s user 0m5.259s sys 0m2.257s ``` `-DARROW_MIMALLOC=ON` ``` $ time RERUN=on ./build/rerun_vrs_example sample.vrs real 0m3.477s user 0m5.015s sys 0m1.291s ``` ### Test * [x] Linux * [x] Mac * [x] Windows, rerun build & test only ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/4094) (if applicable) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/4094) - [Docs preview](https://rerun.io/preview/73f97330c4d4e8cbac82e7e0c0ea7e9d24fcd3c7/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/73f97330c4d4e8cbac82e7e0c0ea7e9d24fcd3c7/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://ref.rerun.io/dev/bench/) - [Wasm size tracking](https://ref.rerun.io/dev/sizes/) --------- Co-authored-by: Andreas Reich <[email protected]>
1 parent c7cfefd commit a143e9d

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

rerun_cpp/CMakeLists.txt

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,13 @@ if(RERUN_DOWNLOAD_AND_BUILD_ARROW)
139139

140140
if(APPLE)
141141
set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow.a)
142+
set(ARROW_BUNDLED_DEPENDENCIES_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow_bundled_dependencies.a)
142143
elseif(UNIX) # if(LINUX) # CMake 3.25
143144
set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow.a)
145+
set(ARROW_BUNDLED_DEPENDENCIES_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow_bundled_dependencies.a)
144146
elseif(WIN32)
145147
set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/arrow_static.lib)
148+
set(ARROW_BUNDLED_DEPENDENCIES_FILE ${ARROW_DOWNLOAD_PATH}/lib/arrow_bundled_dependencies.lib)
146149
else()
147150
message(FATAL_ERROR "Unsupported platform.")
148151
endif()
@@ -155,6 +158,20 @@ if(RERUN_DOWNLOAD_AND_BUILD_ARROW)
155158
set(DARROW_CXXFLAGS "")
156159
endif()
157160

161+
# Workaround for https://github.com/apache/arrow/issues/36117
162+
# This works around linking issues on Windows we got after enabling mimalloc.
163+
if(MSVC)
164+
file(MAKE_DIRECTORY ${ARROW_DOWNLOAD_PATH}/src/arrow_cpp-build/debug/)
165+
file(MAKE_DIRECTORY ${ARROW_DOWNLOAD_PATH}/src/arrow_cpp-build/relwithdebinfo/)
166+
file(MAKE_DIRECTORY ${ARROW_DOWNLOAD_PATH}/src/arrow_cpp-build/release/)
167+
endif()
168+
169+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
170+
set(ARROW_CMAKE_PRESET ninja-debug-minimal)
171+
else()
172+
set(ARROW_CMAKE_PRESET ninja-release-minimal)
173+
endif()
174+
158175
ExternalProject_Add(
159176
arrow_cpp
160177
PREFIX ${ARROW_DOWNLOAD_PATH}
@@ -163,21 +180,22 @@ if(RERUN_DOWNLOAD_AND_BUILD_ARROW)
163180
GIT_SHALLOW true
164181
GIT_PROGRESS true
165182
CMAKE_ARGS
166-
--preset ninja-debug-minimal
167-
-DARROW_IPC=ON
183+
--preset ${ARROW_CMAKE_PRESET}
184+
-DARROW_BOOST_USE_SHARED=OFF
168185
-DARROW_BUILD_SHARED=${ARROW_BUILD_SHARED}
169186
-DARROW_BUILD_STATIC=${ARROW_BUILD_STATIC}
170-
-DCMAKE_INSTALL_PREFIX=${ARROW_DOWNLOAD_PATH}
187+
-DARROW_CXXFLAGS=${DARROW_CXXFLAGS}
188+
-DARROW_IPC=ON
189+
-DARROW_JEMALLOC=OFF # We encountered some build issues with jemalloc, use mimalloc instead.
190+
-DARROW_MIMALLOC=ON
171191
-DARROW_USE_ASAN=${RERUN_USE_ASAN}
172192
-DARROW_USE_TSAN=OFF
173193
-DARROW_USE_UBSAN=OFF
174-
-DARROW_JEMALLOC=OFF
175-
-Dxsimd_SOURCE=BUNDLED
176194
-DBOOST_SOURCE=BUNDLED
177-
-DARROW_BOOST_USE_SHARED=OFF
178-
-DARROW_CXXFLAGS=${DARROW_CXXFLAGS}
195+
-DCMAKE_INSTALL_PREFIX=${ARROW_DOWNLOAD_PATH}
196+
-Dxsimd_SOURCE=BUNDLED
179197
SOURCE_SUBDIR cpp
180-
BUILD_BYPRODUCTS ${ARROW_LIBRARY_FILE}
198+
BUILD_BYPRODUCTS ${ARROW_LIBRARY_FILE} ${ARROW_BUNDLED_DEPENDENCIES_FILE}
181199
)
182200

183201
# arrow_cpp target is not a library. Assemble one from it.
@@ -190,7 +208,17 @@ if(RERUN_DOWNLOAD_AND_BUILD_ARROW)
190208
endif()
191209
else()
192210
add_library(RerunArrowTarget STATIC IMPORTED)
211+
212+
# Need to set the ARROW_STATIC define, otherwise arrow functions are dllimport decorated on Windows.
193213
target_compile_definitions(RerunArrowTarget INTERFACE ARROW_STATIC)
214+
215+
# We have to explicitly opt in the arrow bundled dependencies, otherwise we're missing the symbols for mimalloc.
216+
add_library(RerunArrowTargetBundledDeps STATIC IMPORTED)
217+
add_dependencies(RerunArrowTargetBundledDeps arrow_cpp)
218+
set_target_properties(RerunArrowTargetBundledDeps PROPERTIES
219+
IMPORTED_LOCATION ${ARROW_BUNDLED_DEPENDENCIES_FILE}
220+
)
221+
target_link_libraries(RerunArrowTarget INTERFACE RerunArrowTargetBundledDeps)
194222
endif()
195223

196224
add_dependencies(RerunArrowTarget arrow_cpp)

rerun_cpp/src/rerun/demo_utils.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ namespace rerun {
3030
inline std::vector<T> linspace(T start, T end, size_t num) {
3131
std::vector<T> linspaced(num);
3232
std::generate(linspaced.begin(), linspaced.end(), [&, i = 0]() mutable {
33-
return start + static_cast<T>(i++) * (end - start) / static_cast<T>(num - 1);
33+
return static_cast<T>(
34+
start + static_cast<T>(i++) * (end - start) / static_cast<T>(num - 1)
35+
);
3436
});
3537
return linspaced;
3638
}

0 commit comments

Comments
 (0)