Skip to content

Commit 6928271

Browse files
committed
Try moving R Compute Initialize to static initializer instead of in GetFunctionNames function
1 parent 1d90aeb commit 6928271

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

r/src/compute.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@
2323
#include <arrow/record_batch.h>
2424
#include <arrow/table.h>
2525

26+
#if ARROW_VERSION_MAJOR >= 21
27+
// Initialize Arrow Compute kernels at startup
28+
namespace {
29+
struct ArrowComputeInitializer {
30+
ArrowComputeInitializer() {
31+
auto status = arrow::compute::Initialize();
32+
StopIfNotOk(status);
33+
}
34+
} arrow_compute_initializer;
35+
} // namespace
36+
#endif
37+
2638
std::shared_ptr<arrow::compute::CastOptions> make_cast_options(cpp11::list options);
2739

2840
arrow::compute::ExecContext* gc_context() {
@@ -618,9 +630,6 @@ SEXP compute__CallFunction(std::string func_name, cpp11::list args, cpp11::list
618630

619631
// [[arrow::export]]
620632
std::vector<std::string> compute__GetFunctionNames() {
621-
#if ARROW_VERSION_MAJOR >= 21
622-
StopIfNotOk(arrow::compute::Initialize());
623-
#endif
624633
return arrow::compute::GetFunctionRegistry()->GetFunctionNames();
625634
}
626635

0 commit comments

Comments
 (0)