Skip to content

Commit

Permalink
Improve C++ SDK perf 5x by respecting CMAKE_BUILD_TYPE and enabling m…
Browse files Browse the repository at this point in the history
…imalloc (#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]>
  • Loading branch information
jleibs and Wumpf authored Oct 31, 2023
1 parent c7cfefd commit a143e9d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
44 changes: 36 additions & 8 deletions rerun_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,13 @@ if(RERUN_DOWNLOAD_AND_BUILD_ARROW)

if(APPLE)
set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow.a)
set(ARROW_BUNDLED_DEPENDENCIES_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow_bundled_dependencies.a)
elseif(UNIX) # if(LINUX) # CMake 3.25
set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow.a)
set(ARROW_BUNDLED_DEPENDENCIES_FILE ${ARROW_DOWNLOAD_PATH}/lib/libarrow_bundled_dependencies.a)
elseif(WIN32)
set(ARROW_LIBRARY_FILE ${ARROW_DOWNLOAD_PATH}/lib/arrow_static.lib)
set(ARROW_BUNDLED_DEPENDENCIES_FILE ${ARROW_DOWNLOAD_PATH}/lib/arrow_bundled_dependencies.lib)
else()
message(FATAL_ERROR "Unsupported platform.")
endif()
Expand All @@ -155,6 +158,20 @@ if(RERUN_DOWNLOAD_AND_BUILD_ARROW)
set(DARROW_CXXFLAGS "")
endif()

# Workaround for https://github.com/apache/arrow/issues/36117
# This works around linking issues on Windows we got after enabling mimalloc.
if(MSVC)
file(MAKE_DIRECTORY ${ARROW_DOWNLOAD_PATH}/src/arrow_cpp-build/debug/)
file(MAKE_DIRECTORY ${ARROW_DOWNLOAD_PATH}/src/arrow_cpp-build/relwithdebinfo/)
file(MAKE_DIRECTORY ${ARROW_DOWNLOAD_PATH}/src/arrow_cpp-build/release/)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(ARROW_CMAKE_PRESET ninja-debug-minimal)
else()
set(ARROW_CMAKE_PRESET ninja-release-minimal)
endif()

ExternalProject_Add(
arrow_cpp
PREFIX ${ARROW_DOWNLOAD_PATH}
Expand All @@ -163,21 +180,22 @@ if(RERUN_DOWNLOAD_AND_BUILD_ARROW)
GIT_SHALLOW true
GIT_PROGRESS true
CMAKE_ARGS
--preset ninja-debug-minimal
-DARROW_IPC=ON
--preset ${ARROW_CMAKE_PRESET}
-DARROW_BOOST_USE_SHARED=OFF
-DARROW_BUILD_SHARED=${ARROW_BUILD_SHARED}
-DARROW_BUILD_STATIC=${ARROW_BUILD_STATIC}
-DCMAKE_INSTALL_PREFIX=${ARROW_DOWNLOAD_PATH}
-DARROW_CXXFLAGS=${DARROW_CXXFLAGS}
-DARROW_IPC=ON
-DARROW_JEMALLOC=OFF # We encountered some build issues with jemalloc, use mimalloc instead.
-DARROW_MIMALLOC=ON
-DARROW_USE_ASAN=${RERUN_USE_ASAN}
-DARROW_USE_TSAN=OFF
-DARROW_USE_UBSAN=OFF
-DARROW_JEMALLOC=OFF
-Dxsimd_SOURCE=BUNDLED
-DBOOST_SOURCE=BUNDLED
-DARROW_BOOST_USE_SHARED=OFF
-DARROW_CXXFLAGS=${DARROW_CXXFLAGS}
-DCMAKE_INSTALL_PREFIX=${ARROW_DOWNLOAD_PATH}
-Dxsimd_SOURCE=BUNDLED
SOURCE_SUBDIR cpp
BUILD_BYPRODUCTS ${ARROW_LIBRARY_FILE}
BUILD_BYPRODUCTS ${ARROW_LIBRARY_FILE} ${ARROW_BUNDLED_DEPENDENCIES_FILE}
)

# arrow_cpp target is not a library. Assemble one from it.
Expand All @@ -190,7 +208,17 @@ if(RERUN_DOWNLOAD_AND_BUILD_ARROW)
endif()
else()
add_library(RerunArrowTarget STATIC IMPORTED)

# Need to set the ARROW_STATIC define, otherwise arrow functions are dllimport decorated on Windows.
target_compile_definitions(RerunArrowTarget INTERFACE ARROW_STATIC)

# We have to explicitly opt in the arrow bundled dependencies, otherwise we're missing the symbols for mimalloc.
add_library(RerunArrowTargetBundledDeps STATIC IMPORTED)
add_dependencies(RerunArrowTargetBundledDeps arrow_cpp)
set_target_properties(RerunArrowTargetBundledDeps PROPERTIES
IMPORTED_LOCATION ${ARROW_BUNDLED_DEPENDENCIES_FILE}
)
target_link_libraries(RerunArrowTarget INTERFACE RerunArrowTargetBundledDeps)
endif()

add_dependencies(RerunArrowTarget arrow_cpp)
Expand Down
4 changes: 3 additions & 1 deletion rerun_cpp/src/rerun/demo_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ namespace rerun {
inline std::vector<T> linspace(T start, T end, size_t num) {
std::vector<T> linspaced(num);
std::generate(linspaced.begin(), linspaced.end(), [&, i = 0]() mutable {
return start + static_cast<T>(i++) * (end - start) / static_cast<T>(num - 1);
return static_cast<T>(
start + static_cast<T>(i++) * (end - start) / static_cast<T>(num - 1)
);
});
return linspaced;
}
Expand Down

0 comments on commit a143e9d

Please sign in to comment.