Skip to content

Commit d087b30

Browse files
committed
Use BLAKE3 from LLVM (11% faster)
Results are the same: upstream: SELECT hex(BLAKE3('bar')): F2E897EED7D206CD855D441598FA521ABC75AA96953E97C030C9612C30C1293D llvm: SELECT hex(BLAKE3('bar')): F2E897EED7D206CD855D441598FA521ABC75AA96953E97C030C9612C30C1293D Query for benchmark: SELECT ignore(BLAKE3(materialize('Lorem ipsum dolor sit amet, consectetur adipiscing elit'))) FROM numbers(1000000000) FORMAT `Null` upstream : Elapsed: 2.494 sec. Processed 31.13 million rows, 249.08 MB (12.48 million rows/s., 99.86 MB/s.) upstream + rust lto: ~14.00 million rows/s llvm : Elapsed: 3.053 sec. Processed 43.24 million rows, 345.88 MB (14.16 million rows/s., 113.28 MB/s.) And note, that now, integrating_rust_libraries.md became deprecated. P.S. LLVM implementation had been choosen over Rust + LTO, because there are issues with linking multiple Rust libraries together with LTO: - https://alanwu.space/post/symbol-hygiene/ - rust-lang/rust#44322
1 parent 3f0c360 commit d087b30

File tree

8 files changed

+10
-200
lines changed

8 files changed

+10
-200
lines changed

rust/BLAKE3/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

rust/BLAKE3/Cargo.lock

Lines changed: 0 additions & 92 deletions
This file was deleted.

rust/BLAKE3/Cargo.toml

Lines changed: 0 additions & 13 deletions
This file was deleted.

rust/BLAKE3/include/blake3.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

rust/BLAKE3/src/lib.rs

Lines changed: 0 additions & 55 deletions
This file was deleted.

rust/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,4 @@ function(add_rust_subdirectory src)
6767
VERBATIM)
6868
endfunction()
6969

70-
add_rust_subdirectory (BLAKE3)
7170
add_rust_subdirectory (skim)

src/Functions/FunctionsHashing.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <farmhash.h>
55
#include <metrohash.h>
66
#include <wyhash.h>
7+
#include <llvm/ADT/StringRef.h>
78
#include <MurmurHash2.h>
89
#include <MurmurHash3.h>
910

@@ -15,10 +16,6 @@
1516
#endif
1617
#include <xxhash.h>
1718

18-
#if USE_BLAKE3
19-
# include <blake3.h>
20-
#endif
21-
2219
#include <Common/SipHash.h>
2320
#include <Common/typeid_cast.h>
2421
#include <Common/safe_cast.h>
@@ -57,6 +54,10 @@
5754
#include <base/bit_cast.h>
5855
#include <base/unaligned.h>
5956

57+
#if USE_BLAKE3
58+
#include <llvm-c/blake3.h>
59+
#endif
60+
6061
namespace DB
6162
{
6263

@@ -819,18 +820,10 @@ struct ImplBLAKE3
819820
#else
820821
static void apply(const char * begin, const size_t size, unsigned char* out_char_data)
821822
{
822-
#if defined(MEMORY_SANITIZER)
823-
auto err_msg = blake3_apply_shim_msan_compat(begin, safe_cast<uint32_t>(size), out_char_data);
824-
__msan_unpoison(out_char_data, length);
825-
#else
826-
auto err_msg = blake3_apply_shim(begin, safe_cast<uint32_t>(size), out_char_data);
827-
#endif
828-
if (err_msg != nullptr)
829-
{
830-
auto err_st = std::string(err_msg);
831-
blake3_free_char_pointer(err_msg);
832-
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Function returned error message: {}", err_st);
833-
}
823+
llvm_blake3_hasher hasher;
824+
llvm_blake3_hasher_init(&hasher);
825+
llvm_blake3_hasher_update(&hasher, begin, size);
826+
llvm_blake3_hasher_finalize(&hasher, out_char_data, length);
834827
}
835828
#endif
836829
};

src/configure_config.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ endif()
1919
if (TARGET ch_contrib::rdkafka)
2020
set(USE_RDKAFKA 1)
2121
endif()
22-
if (TARGET ch_rust::blake3)
23-
set(USE_BLAKE3 1)
24-
endif()
2522
if (TARGET ch_rust::skim)
2623
set(USE_SKIM 1)
2724
endif()
@@ -99,6 +96,7 @@ if (TARGET ch_contrib::ulid)
9996
endif()
10097
if (TARGET ch_contrib::llvm)
10198
set(USE_EMBEDDED_COMPILER 1)
99+
set(USE_BLAKE3 1)
102100
endif()
103101
if (TARGET ch_contrib::unixodbc)
104102
set(USE_ODBC 1)

0 commit comments

Comments
 (0)