Skip to content

Commit d4f2b02

Browse files
Eugene Linfacebook-github-bot
authored andcommitted
Lower JS Thread Priority by 10
Summary: ## Changelog: [Internal]: [Threading][Added] - Add option to change thread priority D73074402 handles lowering priority for IWM js and granite threads. this diff handles lowering priority for in game panel js thread JS thread inherits parent thread priority by default lowering priority by 10 Reviewed By: rshest Differential Revision: D72842049 fbshipit-source-id: 6797f7c8406a410956c64bb08a12d2b26c100040
1 parent a6f5100 commit d4f2b02

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

packages/react-native/ReactCxxPlatform/react/threading/MessageQueueThreadImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ constexpr char MessageQueueThreadFactoryKey[] = "MessageQueueThreadFactoryKey";
2525
class MessageQueueThreadImpl : public MessageQueueThread {
2626
public:
2727
MessageQueueThreadImpl() noexcept = default;
28+
explicit MessageQueueThreadImpl(int priorityOffset) noexcept
29+
: taskDispatchThread_("MessageQueue", priorityOffset) {}
2830

2931
~MessageQueueThreadImpl() noexcept override = default;
3032

packages/react-native/ReactCxxPlatform/react/threading/TaskDispatchThread.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,43 @@
77

88
#include "TaskDispatchThread.h"
99

10+
#include <folly/portability/SysResource.h>
1011
#include <folly/system/ThreadName.h>
1112
#include <chrono>
1213
#include <future>
1314
#include <utility>
1415

16+
#include <glog/logging.h>
17+
1518
#ifdef ANDROID
1619
#include <fbjni/fbjni.h>
20+
#include <sys/syscall.h>
1721
#endif
1822

1923
namespace facebook::react {
2024

21-
TaskDispatchThread::TaskDispatchThread(std::string threadName) noexcept
25+
TaskDispatchThread::TaskDispatchThread(
26+
std::string threadName,
27+
int priorityOffset) noexcept
2228
: threadName_(std::move(threadName)) {
2329
#ifdef ANDROID
2430
// Attaches the thread to JVM just in case anything calls out to Java
2531
thread_ = std::thread([&]() {
26-
facebook::jni::ThreadScope::WithClassLoader([&]() { loop(); });
32+
facebook::jni::ThreadScope::WithClassLoader([&]() {
33+
int result = setpriority(
34+
PRIO_PROCESS,
35+
static_cast<pid_t>(::syscall(SYS_gettid)),
36+
priorityOffset);
37+
38+
if (result != 0) {
39+
LOG(INFO) << " setCurrentThreadPriority failed with pri errno: "
40+
<< errno;
41+
}
42+
43+
loop();
44+
});
2745
});
46+
2847
#else
2948
thread_ = std::thread(&TaskDispatchThread::loop, this);
3049
#endif

packages/react-native/ReactCxxPlatform/react/threading/TaskDispatchThread.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class TaskDispatchThread {
2525
using TaskFn = std::function<void()>;
2626
using TimePoint = std::chrono::time_point<std::chrono::system_clock>;
2727

28-
TaskDispatchThread(std::string threadName = "") noexcept;
28+
TaskDispatchThread(
29+
std::string threadName = "",
30+
int priorityOffset = 0) noexcept;
31+
2932
~TaskDispatchThread() noexcept;
3033

3134
/** Return true if the current thread is the same as this looper's thread. */

0 commit comments

Comments
 (0)