一款高性能基于 JIT 的 C++ 表达式/脚本执行引擎,支持 SIMD 向量化
RapidUDF
RapidUDF is a high-performance SIMD vectorized expression/script computation execution engine library designed for online systems. It can be used in scenarios requiring high performance and flexibility such as rule engines, storage systems, and feature computation.
Compilation requires a compiler that supports C++17
Add in WORKSPACE:
git_repository(
name = "rapidudf",
remote = "https://github.com/yinqiwen/rapidudf.git",
commit = "...",
)
load("@rapidudf//:rapidudf.bzl", "rapidudf_workspace")
rapidudf_workspace()Add in the BUILD file for relevant code compilation rules:
cc_library(
name = "mylib",
srcs = ["mylib.cc"],
hdrs = [
"mylib.h",
],
deps = [
"@rapidudf",
],
)First, compile and install rapidudf
cd
mkdir build; cd build;
cmake ..
make installAdd the following to the CMake configuration of the related project:
find_package(rapidudf REQUIRED)
....
# link rapidudf
target_link_libraries(mylib PRIVATE rapidudf::rapidudf)…cpp #include "rapidudf/rapidudf.h"
using namespace rapidudf; struct Student { std::string name; uint16_t age = 0; float score = 0; bool gender = false; }; RUDF_STRUCT_FIELDS(Student, name, age, score, gender) int main() { // 1. Create table schema auto schema = table::TableSchema::GetOrCreate("Student", [](table::TableSchema* s) { std::ignore = s->AddColumns(); });
// 2. UDF string, table generic format where TABLE_NAME must match the previously created table schema name // table supports filter/order_by/topk/take/group_by/concat/distinct/map/flatmap/merge, etc. operations std::string source = R"( table select_students(Context ctx, table x) { auto filtered = x.filter(x.score >90 && x.age students; for (size_t i = 0; i NewTable(ctx); std::ignore = table->AddRows(students);
// 5. Execute function try { auto result_table = f(ctx, table.get()); auto result_scores = result_table->Get("score").value(); auto result_names = result_table->Get("name").value(); auto result_ages = result_table->Get("age").value(); auto result_genders = result_table->Get("gender").value(); for (size_t i = 0; i , std::vector, std::vector`.
Here is an example of creating a vector table based on Protobuf; Examples based on flatbuffers can be found in fbs_vector_table_udf; Examples based on struct can be found in struct_vector_table_udf;
…Theoretically, the acceleration ratio should be the multiple of the AVX2 register width to the float width, which is 8;
Actual results are as follows, showing that the acceleration ratio has exceeded 8 times, reaching 10.5:
Benchmark Time CPU Iterations
-------------------------------------------------------------------------
BM_native_wilson_ctr 69961 ns 69957 ns 9960
BM_rapidudf_vector_wilson_ctr 6661 ns 6659 ns 105270暂无开放 Issues,或尚未同步最近议题。