Skip to content

Commit b84ce20

Browse files
authored
chore(Worklets): remove runtime-string association from RuntimeManager (#8443)
## Summary I'm removing the association of runtime name - worklet runtime from runtime manager. It was added as a possibility for future extension but since the names of the runtimes don't have to be unique and there are already unique IDs for the runtimes, the association is obsolete. It's safe to delete it since it's not used and it's a private API. ## Test plan CI
1 parent c7ff582 commit b84ce20

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
#include <worklets/WorkletRuntime/RuntimeData.h>
22

3+
namespace worklets {
4+
namespace RuntimeData {
5+
36
const std::string uiRuntimeName{"UI"};
7+
8+
} // namespace RuntimeData
9+
} // namespace worklets

packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/RuntimeData.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
#include <string>
44

5+
namespace worklets {
6+
namespace RuntimeData {
7+
58
/**
69
* Unused, but kept for possible future use.
710
*/
811
constexpr uint64_t rnRuntimeId{0};
912
constexpr uint64_t uiRuntimeId{1};
1013
extern const std::string uiRuntimeName;
14+
15+
}; // namespace RuntimeData
16+
} // namespace worklets

packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/RuntimeManager.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ std::shared_ptr<WorkletRuntime> RuntimeManager::getRuntime(uint64_t runtimeId) {
1313
return nullptr;
1414
}
1515

16-
std::shared_ptr<WorkletRuntime> RuntimeManager::getRuntime(
17-
const std::string &name) {
18-
std::shared_lock lock(weakRuntimesMutex_);
19-
if (nameToRuntimeId_.contains(name)) {
20-
return getRuntime(nameToRuntimeId_.at(name));
21-
}
22-
return nullptr;
23-
}
24-
2516
#ifdef WORKLETS_BUNDLE_MODE
2617
std::shared_ptr<WorkletRuntime> RuntimeManager::getRuntime(
2718
jsi::Runtime *runtime) {
@@ -49,7 +40,7 @@ std::vector<std::shared_ptr<WorkletRuntime>> RuntimeManager::getAllRuntimes() {
4940
}
5041

5142
std::shared_ptr<WorkletRuntime> RuntimeManager::getUIRuntime() {
52-
return getRuntime(uiRuntimeId);
43+
return getRuntime(RuntimeData::uiRuntimeId);
5344
}
5445

5546
std::shared_ptr<WorkletRuntime> RuntimeManager::createWorkletRuntime(
@@ -70,7 +61,7 @@ std::shared_ptr<WorkletRuntime> RuntimeManager::createWorkletRuntime(
7061
workletRuntime->runGuarded(initializer);
7162
}
7263

73-
registerRuntime(runtimeId, name, workletRuntime);
64+
registerRuntime(runtimeId, workletRuntime);
7465

7566
return workletRuntime;
7667
}
@@ -79,9 +70,13 @@ std::shared_ptr<WorkletRuntime> RuntimeManager::createUninitializedUIRuntime(
7970
const std::shared_ptr<MessageQueueThread> &jsQueue,
8071
const std::shared_ptr<AsyncQueue> &uiAsyncQueue) {
8172
const auto uiRuntime = std::make_shared<WorkletRuntime>(
82-
uiRuntimeId, jsQueue, uiRuntimeName, uiAsyncQueue);
73+
RuntimeData::uiRuntimeId,
74+
jsQueue,
75+
RuntimeData::uiRuntimeName,
76+
uiAsyncQueue,
77+
/*enableEventLoop*/ false);
8378

84-
registerRuntime(uiRuntimeId, uiRuntimeName, uiRuntime);
79+
registerRuntime(RuntimeData::uiRuntimeId, uiRuntime);
8580

8681
return uiRuntime;
8782
}
@@ -92,11 +87,9 @@ uint64_t RuntimeManager::getNextRuntimeId() {
9287

9388
void RuntimeManager::registerRuntime(
9489
const uint64_t runtimeId,
95-
const std::string &name,
9690
const std::shared_ptr<WorkletRuntime> &workletRuntime) {
9791
std::unique_lock lock(weakRuntimesMutex_);
9892
weakRuntimes_[runtimeId] = workletRuntime;
99-
nameToRuntimeId_[name] = runtimeId;
10093
#ifdef WORKLETS_BUNDLE_MODE
10194
runtimeAddressToRuntimeId_[&workletRuntime->getJSIRuntime()] = runtimeId;
10295
#endif // WORKLETS_BUNDLE_MODE

packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/RuntimeManager.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class JSIWorkletsModuleProxy;
2323
class RuntimeManager {
2424
public:
2525
std::shared_ptr<WorkletRuntime> getRuntime(uint64_t runtimeId);
26-
std::shared_ptr<WorkletRuntime> getRuntime(const std::string &name);
2726
#ifdef WORKLETS_BUNDLE_MODE
2827
std::shared_ptr<WorkletRuntime> getRuntime(jsi::Runtime *runtime);
2928
#endif // WORKLETS_BUNDLE_MODE
@@ -48,13 +47,11 @@ class RuntimeManager {
4847

4948
void registerRuntime(
5049
const uint64_t runtimeId,
51-
const std::string &name,
5250
const std::shared_ptr<WorkletRuntime> &workletRuntime);
5351

54-
std::atomic_uint64_t nextRuntimeId_{uiRuntimeId + 1};
52+
std::atomic_uint64_t nextRuntimeId_{RuntimeData::uiRuntimeId + 1};
5553
std::map<uint64_t, std::weak_ptr<WorkletRuntime>> weakRuntimes_;
5654
std::shared_mutex weakRuntimesMutex_;
57-
std::map<std::string, uint64_t> nameToRuntimeId_;
5855
#ifdef WORKLETS_BUNDLE_MODE
5956
std::map<jsi::Runtime *, uint64_t> runtimeAddressToRuntimeId_;
6057
#endif // WORKLETS_BUNDLE_MODE

packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ WorkletRuntime::WorkletRuntime(
8181
queue_(queue) {
8282
jsi::Runtime &rt = *runtime_;
8383
WorkletRuntimeCollector::install(rt);
84-
if (enableEventLoop && name != uiRuntimeName) {
84+
if (enableEventLoop) {
8585
eventLoop_ = std::make_shared<EventLoop>(name_, runtime_, queue_);
8686
eventLoop_->run();
8787
}

0 commit comments

Comments
 (0)