ktprime / emhash

Fast and memory efficient c++ flat hash map/set
MIT License
471 stars 35 forks source link

No `aligned_alloc` on Android #27

Closed blueloveTH closed 1 year ago

blueloveTH commented 1 year ago

Hi!

I have tried to update my project to use the newest version of hash_table8.cpp.

However, things are broken on Android.

https://github.com/blueloveTH/pocketpy/actions/runs/4114180187/jobs/7101213960

Logs

"Install NDK (Side by side) 21.4.7075529 (revision: 21.4.7075529)" finished.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':pocketpy:buildCMakeRelWithDebInfo[arm64-v8a]'.
> Build command failed.
  Error while executing process /usr/local/lib/android/sdk/cmake/3.18.1/bin/ninja with arguments {-C /home/runner/work/pocketpy/pocketpy/plugins/flutter/android/.cxx/RelWithDebInfo/[39](https://github.com/blueloveTH/pocketpy/actions/runs/4111274941/jobs/7094875802#step:5:40)31b6d3/arm64-v8a pocketpy}
  ninja: Entering directory `/home/runner/work/pocketpy/pocketpy/plugins/flutter/android/.cxx/RelWithDebInfo/3931b6d3/arm64-v8a'
  [1/2] Building CXX object CMakeFiles/pocketpy.dir/pocketpy.cpp.o
  FAILED: CMakeFiles/pocketpy.dir/pocketpy.cpp.o 
  /usr/local/lib/android/sdk/ndk/21.4.7075[52](https://github.com/blueloveTH/pocketpy/actions/runs/4111274941/jobs/7094875802#step:5:53)9/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot -DDART_SHARED_LIB -Dpocketpy_EXPORTS  -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -O2 -g -DNDEBUG -fPIC -fno-rtti -std=gnu++17 -MD -MT CMakeFiles/pocketpy.dir/pocketpy.cpp.o -MF CMakeFiles/pocketpy.dir/pocketpy.cpp.o.d -o CMakeFiles/pocketpy.dir/pocketpy.cpp.o -c /home/runner/work/pocketpy/pocketpy/plugins/flutter/src/pocketpy.cpp
  In file included from /home/runner/work/pocketpy/pocketpy/plugins/flutter/src/pocketpy.cpp:1:
  /home/runner/work/pocketpy/pocketpy/plugins/flutter/src/pocketpy.h:1080:26: error: use of undeclared identifier 'aligned_alloc'
          auto new_pairs = aligned_alloc(32, (uint64_t)num_buckets * sizeof(value_type));
                           ^
  /home/runner/work/pocketpy/pocketpy/plugins/flutter/src/pocketpy.h:1155:31: warning: shift count >= width of type [-Wshift-count-overflow]
              num_buckets = 2ul << (sizeof(KeyT) * 8);
                                ^  ~~~~~~~~~~~~~~~~~~

Seems there is no aligned_alloc in Android STL.

blueloveTH commented 1 year ago

Although other platforms work well, there is a significant performance decline(~30%) compared with v1.6.3.

My test case on Linux is ~2.0s on v1.6.3 while on v1.6.4 the time is ~3.0s.

I tested for several times. The only change is in this commit↓↓ https://github.com/blueloveTH/pocketpy/commit/5a1977633155738a10628aba2cc9888a019d4835

By the way, I am not sure about the differences between hash_table5/6/7/8. Is there any detailed documentations?

ktprime commented 1 year ago

thanks for report the issiue. I'll fixed it later. for small key(integer, pointer) emhash7 is better. emhash5 is optimizated for finding hit. so u can try bench it on your system.

The folllow link which gives u a detail comparsion between emhash7 and emhash8. https://martin.ankerl.com/2022/08/27/hashmap-bench-01/#benchmark-results-table

ktprime commented 1 year ago

image

blueloveTH commented 1 year ago

Thanks for your explanation~