From e72a8b1852c3ea0a2c72849af21b0b1e0d046bea Mon Sep 17 00:00:00 2001 From: chmjkb Date: Wed, 3 Dec 2025 09:58:38 +0100 Subject: [PATCH 1/2] fix: set openCV threads to 0 --- .../rnexecutorch/RnExecutorchInstaller.cpp | 16 ---------------- .../rnexecutorch/threads/GlobalThreadPool.h | 2 ++ 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/packages/react-native-executorch/common/rnexecutorch/RnExecutorchInstaller.cpp b/packages/react-native-executorch/common/rnexecutorch/RnExecutorchInstaller.cpp index 95f6e9e55..c25fbd13f 100644 --- a/packages/react-native-executorch/common/rnexecutorch/RnExecutorchInstaller.cpp +++ b/packages/react-native-executorch/common/rnexecutorch/RnExecutorchInstaller.cpp @@ -108,22 +108,6 @@ void RnExecutorchInstaller::injectJSIBindings( threads::utils::unsafeSetupThreadPool(); threads::GlobalThreadPool::initialize(); - -#if defined(__ANDROID__) && defined(__aarch64__) - auto num_of_perf_cores = - ::executorch::extension::cpuinfo::get_num_performant_cores(); - log(LOG_LEVEL::Info, "Detected ", num_of_perf_cores, " performant cores"); - // setting num_of_cores to floor(num_of_perf_cores / 2) + 1) because depending - // on cpu arch as when possible we want to leave at least 2 performant cores - // for other tasks (setting more actually results in drop of performance). For - // older devices (i.e. samsung s22) resolves to 3 cores, and for newer ones - // (like OnePlus 12) resolves to 4, which when benchamrked gives highest - // throughput. - auto num_of_cores = static_cast(num_of_perf_cores / 2) + 1; - ::executorch::extension::threadpool::get_threadpool() - ->_unsafe_reset_threadpool(num_of_cores); - log(LOG_LEVEL::Info, "Configuring xnnpack for ", num_of_cores, " threads"); -#endif } } // namespace rnexecutorch diff --git a/packages/react-native-executorch/common/rnexecutorch/threads/GlobalThreadPool.h b/packages/react-native-executorch/common/rnexecutorch/threads/GlobalThreadPool.h index 8b61080f8..5abc3469b 100644 --- a/packages/react-native-executorch/common/rnexecutorch/threads/GlobalThreadPool.h +++ b/packages/react-native-executorch/common/rnexecutorch/threads/GlobalThreadPool.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,7 @@ class GlobalThreadPool { numThreads, "threads"); instance = std::make_unique(numThreads.value(), config); + cv::setNumThreads(0); }); } From b4afa65f0f4094ba5c8dfd6b898ebc642b5a2096 Mon Sep 17 00:00:00 2001 From: chmjkb Date: Wed, 3 Dec 2025 10:18:38 +0100 Subject: [PATCH 2/2] chore: add a comment --- .../common/rnexecutorch/threads/GlobalThreadPool.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/react-native-executorch/common/rnexecutorch/threads/GlobalThreadPool.h b/packages/react-native-executorch/common/rnexecutorch/threads/GlobalThreadPool.h index 5abc3469b..50025eeeb 100644 --- a/packages/react-native-executorch/common/rnexecutorch/threads/GlobalThreadPool.h +++ b/packages/react-native-executorch/common/rnexecutorch/threads/GlobalThreadPool.h @@ -39,6 +39,8 @@ class GlobalThreadPool { numThreads, "threads"); instance = std::make_unique(numThreads.value(), config); + // Disable OpenCV's internal threading to prevent it from overriding our + // thread pool configuration, which would cause degraded performance cv::setNumThreads(0); }); }