Skip to content

Commit 17b7d16

Browse files
authored
[Fabric] Enable concurrentRoot (#12367)
* [Fabric] Enable concurrentRoot * feedback * fix * format
1 parent 0c368cd commit 17b7d16

14 files changed

+220
-95
lines changed

.vscode/settings.json

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,90 @@
1717
"utility": "cpp",
1818
"ratio": "cpp",
1919
"memory": "cpp",
20-
"array": "cpp"
20+
"array": "cpp",
21+
"algorithm": "cpp",
22+
"any": "cpp",
23+
"atomic": "cpp",
24+
"bit": "cpp",
25+
"bitset": "cpp",
26+
"cctype": "cpp",
27+
"charconv": "cpp",
28+
"chrono": "cpp",
29+
"cinttypes": "cpp",
30+
"clocale": "cpp",
31+
"cmath": "cpp",
32+
"compare": "cpp",
33+
"complex": "cpp",
34+
"concepts": "cpp",
35+
"condition_variable": "cpp",
36+
"coroutine": "cpp",
37+
"csignal": "cpp",
38+
"cstdarg": "cpp",
39+
"cstddef": "cpp",
40+
"cstdint": "cpp",
41+
"cstdio": "cpp",
42+
"cstdlib": "cpp",
43+
"cstring": "cpp",
44+
"ctime": "cpp",
45+
"cwchar": "cpp",
46+
"exception": "cpp",
47+
"forward_list": "cpp",
48+
"fstream": "cpp",
49+
"functional": "cpp",
50+
"future": "cpp",
51+
"initializer_list": "cpp",
52+
"iomanip": "cpp",
53+
"ios": "cpp",
54+
"iosfwd": "cpp",
55+
"iostream": "cpp",
56+
"istream": "cpp",
57+
"iterator": "cpp",
58+
"limits": "cpp",
59+
"map": "cpp",
60+
"memory_resource": "cpp",
61+
"mutex": "cpp",
62+
"new": "cpp",
63+
"numeric": "cpp",
64+
"optional": "cpp",
65+
"ostream": "cpp",
66+
"queue": "cpp",
67+
"random": "cpp",
68+
"ranges": "cpp",
69+
"scoped_allocator": "cpp",
70+
"set": "cpp",
71+
"shared_mutex": "cpp",
72+
"source_location": "cpp",
73+
"span": "cpp",
74+
"sstream": "cpp",
75+
"stack": "cpp",
76+
"stdexcept": "cpp",
77+
"stop_token": "cpp",
78+
"streambuf": "cpp",
79+
"string": "cpp",
80+
"strstream": "cpp",
81+
"system_error": "cpp",
82+
"thread": "cpp",
83+
"tuple": "cpp",
84+
"type_traits": "cpp",
85+
"typeindex": "cpp",
86+
"typeinfo": "cpp",
87+
"unordered_map": "cpp",
88+
"unordered_set": "cpp",
89+
"variant": "cpp",
90+
"xfacet": "cpp",
91+
"xhash": "cpp",
92+
"xiosbase": "cpp",
93+
"xlocale": "cpp",
94+
"xlocbuf": "cpp",
95+
"xlocinfo": "cpp",
96+
"xlocmes": "cpp",
97+
"xlocmon": "cpp",
98+
"xlocnum": "cpp",
99+
"xloctime": "cpp",
100+
"xmemory": "cpp",
101+
"xtr1common": "cpp",
102+
"xtree": "cpp",
103+
"xutility": "cpp"
21104
},
22105
"search.exclude": {
23106
"**/dist/**/*.js": true,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "[Fabric] Enable concurrentRoot",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative/Fabric/Composition/CompositionRootView.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,12 @@ void CompositionRootView::ShowInstanceLoaded() noexcept {
288288

289289
auto rootTag = ::Microsoft::ReactNative::getNextRootViewTag();
290290
SetTag(rootTag);
291-
uiManager->startSurface(
292-
*this, rootTag, JSComponentName(), DynamicWriter::ToDynamic(Mso::Copy(m_reactViewOptions.InitialProps())));
291+
auto initProps = DynamicWriter::ToDynamic(Mso::Copy(m_reactViewOptions.InitialProps()));
292+
if (initProps.isNull()) {
293+
initProps = folly::dynamic::object();
294+
}
295+
initProps["concurrentRoot"] = true;
296+
uiManager->startSurface(*this, rootTag, JSComponentName(), initProps);
293297

294298
m_isJSViewAttached = true;
295299
}

vnext/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ void FabricUIManager::installFabricUIManager() noexcept {
7676
return std::make_unique<SynchronousEventBeat>(ownerBox, context, runtimeExecutor, runtimeScheduler);
7777
};
7878
toolbox.synchronousEventBeatFactory = synchronousBeatFactory;
79+
runtimeExecutor = [runtimeScheduler](std::function<void(facebook::jsi::Runtime & runtime)> &&callback) {
80+
runtimeScheduler->scheduleWork(std::move(callback));
81+
};
7982
} else {
8083
facebook::react::EventBeat::Factory synchronousBeatFactory =
8184
[runtimeExecutor, context = m_context](facebook::react::EventBeat::SharedOwnerBox const &ownerBox) {

vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#endif
2727
#include <JSCallInvokerScheduler.h>
2828
#include <QuirkSettings.h>
29-
#include <SchedulerSettings.h>
3029
#include <Shared/DevServerHelper.h>
3130
#include <Views/ViewManager.h>
3231
#include <dispatchQueue/dispatchQueue.h>
@@ -88,10 +87,11 @@
8887
#include "ChakraRuntimeHolder.h"
8988

9089
#include <CppRuntimeOptions.h>
90+
#include <CreateInstance.h>
9191
#include <CreateModules.h>
9292
#include <Utils/Helpers.h>
9393
#include <react/renderer/runtimescheduler/RuntimeScheduler.h>
94-
#include <react/renderer/runtimescheduler/RuntimeSchedulerBinding.h>
94+
#include <react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h>
9595
#include "CrashManager.h"
9696
#include "JsiApi.h"
9797
#include "ReactCoreInjection.h"
@@ -569,6 +569,12 @@ void ReactInstanceWin::Initialize() noexcept {
569569

570570
m_jsiRuntimeHolder = devSettings->jsiRuntimeHolder;
571571

572+
bool useRuntimeScheduler =
573+
winrt::Microsoft::ReactNative::implementation::QuirkSettings::GetUseRuntimeScheduler(
574+
winrt::Microsoft::ReactNative::ReactPropertyBag(m_reactContext->Properties()));
575+
576+
devSettings->useRuntimeScheduler = useRuntimeScheduler;
577+
572578
try {
573579
// We need to keep the instance wrapper alive as its destruction shuts down the native queue.
574580
m_options.TurboModuleProvider->SetReactContext(
@@ -587,6 +593,7 @@ void ReactInstanceWin::Initialize() noexcept {
587593
std::move(cxxModules),
588594
m_options.TurboModuleProvider,
589595
m_options.TurboModuleProvider->LongLivedObjectCollection(),
596+
m_reactContext->Properties(),
590597
std::make_unique<BridgeUIBatchInstanceCallback>(weakThis),
591598
m_jsMessageThread.Load(),
592599
m_nativeMessageThread.Load(),
@@ -604,33 +611,6 @@ void ReactInstanceWin::Initialize() noexcept {
604611
instance = m_instance.Load(),
605612
turboModuleProvider = m_options.TurboModuleProvider,
606613
useWebDebugger = m_options.UseWebDebugger()]() noexcept {
607-
if (!useWebDebugger) {
608-
#ifdef USE_FABRIC
609-
Microsoft::ReactNative::SchedulerSettings::SetRuntimeExecutor(
610-
winrt::Microsoft::ReactNative::ReactPropertyBag(reactContext->Properties()),
611-
instanceWrapper->GetInstance()->getRuntimeExecutor());
612-
#endif
613-
614-
if (winrt::Microsoft::ReactNative::implementation::QuirkSettings::GetUseRuntimeScheduler(
615-
winrt::Microsoft::ReactNative::ReactPropertyBag(reactContext->Properties()))) {
616-
std::shared_ptr<facebook::react::RuntimeScheduler> runtimeScheduler =
617-
std::make_shared<facebook::react::RuntimeScheduler>(
618-
instanceWrapper->GetInstance()->getRuntimeExecutor());
619-
620-
facebook::react::RuntimeSchedulerBinding::createAndInstallIfNeeded(
621-
*jsiRuntimeHolder->getRuntime().get(), runtimeScheduler);
622-
Microsoft::ReactNative::SchedulerSettings::SetRuntimeScheduler(
623-
ReactPropertyBag(reactContext->Properties()), runtimeScheduler);
624-
}
625-
}
626-
627-
#ifdef USE_FABRIC
628-
// Eagerly init the FabricUI binding
629-
if (!useWebDebugger) {
630-
turboModuleProvider->getModule("FabricUIManagerBinding", instance->getJSCallInvoker());
631-
}
632-
#endif
633-
634614
if (onCreated) {
635615
onCreated.Get()->Invoke(reactContext);
636616
}

vnext/Microsoft.ReactNative/TurboModulesProvider.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ std::vector<std::string> TurboModulesProvider::getEagerInitModuleNames() noexcep
384384
if (it != m_moduleProviders.end()) {
385385
eagerModules.push_back("UIManager");
386386
}
387+
it = m_moduleProviders.find("FabricUIManagerBinding");
388+
if (it != m_moduleProviders.end()) {
389+
eagerModules.push_back("FabricUIManagerBinding");
390+
}
387391
return eagerModules;
388392
}
389393

vnext/Shared/CreateInstance.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
#pragma once
5+
6+
#include <InstanceManager.h>
7+
#include <winrt/Microsoft.ReactNative.h>
8+
9+
namespace facebook::react {
10+
11+
std::shared_ptr<InstanceWrapper> CreateReactInstance(
12+
std::shared_ptr<Instance> &&instance,
13+
std::string &&jsBundleRelativePath,
14+
std::vector<
15+
std::tuple<std::string, facebook::xplat::module::CxxModule::Provider, std::shared_ptr<MessageQueueThread>>>
16+
&&cxxModules,
17+
std::shared_ptr<TurboModuleRegistry> turboModuleRegistry,
18+
std::shared_ptr<facebook::react::LongLivedObjectCollection> longLivedObjectCollection,
19+
const winrt::Microsoft::ReactNative::IReactPropertyBag &propertyBag,
20+
std::unique_ptr<InstanceCallback> &&callback,
21+
std::shared_ptr<MessageQueueThread> jsQueue,
22+
std::shared_ptr<MessageQueueThread> nativeQueue,
23+
std::shared_ptr<DevSettings> devSettings) noexcept;
24+
25+
} // namespace facebook::react

vnext/Shared/DevSettings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ struct DevSettings {
105105

106106
// OC:8368383 - Memory leak under investigation.
107107
bool useWebSocketTurboModule{false};
108+
109+
// Enable concurrent mode by installing runtimeScheduler
110+
bool useRuntimeScheduler{false};
108111
};
109112

110113
} // namespace react

vnext/Shared/InstanceManager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ std::shared_ptr<InstanceWrapper> CreateReactInstance(
4141
std::move(jsBundleBasePath),
4242
std::move(cxxModules),
4343
std::move(turboModuleRegistry),
44-
nullptr,
44+
nullptr, // longLivedObjectCollection
45+
nullptr, // PropertyBag
4546
std::move(callback),
4647
std::move(jsQueue),
4748
std::move(nativeQueue),
@@ -59,6 +60,7 @@ std::shared_ptr<InstanceWrapper> CreateReactInstance(
5960
&&cxxModules,
6061
std::shared_ptr<TurboModuleRegistry> turboModuleRegistry,
6162
std::shared_ptr<facebook::react::LongLivedObjectCollection> longLivedObjectCollection,
63+
const winrt::Microsoft::ReactNative::IReactPropertyBag &propertyBag,
6264
std::unique_ptr<InstanceCallback> &&callback,
6365
std::shared_ptr<MessageQueueThread> jsQueue,
6466
std::shared_ptr<MessageQueueThread> nativeQueue,
@@ -70,6 +72,7 @@ std::shared_ptr<InstanceWrapper> CreateReactInstance(
7072
std::move(cxxModules),
7173
std::move(turboModuleRegistry),
7274
std::move(longLivedObjectCollection),
75+
propertyBag,
7376
std::move(callback),
7477
std::move(jsQueue),
7578
std::move(nativeQueue),

vnext/Shared/InstanceManager.h

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ namespace folly {
1818
struct dynamic;
1919
}
2020

21-
namespace facebook {
22-
23-
namespace react {
21+
namespace facebook::react {
2422

2523
class Instance;
2624
struct InstanceCallback;
2725
class MessageQueueThread;
2826
class ModuleRegistry;
2927
class IUIManager;
3028
class TurboModuleRegistry;
29+
class RuntimeScheduler;
3130

3231
struct InstanceWrapper {
3332
virtual const std::shared_ptr<Instance> &GetInstance() const noexcept = 0;
@@ -52,19 +51,6 @@ std::shared_ptr<InstanceWrapper> CreateReactInstance(
5251
std::shared_ptr<MessageQueueThread> nativeQueue,
5352
std::shared_ptr<DevSettings> devSettings) noexcept;
5453

55-
std::shared_ptr<InstanceWrapper> CreateReactInstance(
56-
std::shared_ptr<Instance> &&instance,
57-
std::string &&jsBundleRelativePath,
58-
std::vector<
59-
std::tuple<std::string, facebook::xplat::module::CxxModule::Provider, std::shared_ptr<MessageQueueThread>>>
60-
&&cxxModules,
61-
std::shared_ptr<TurboModuleRegistry> turboModuleRegistry,
62-
std::shared_ptr<facebook::react::LongLivedObjectCollection> longLivedObjectCollection,
63-
std::unique_ptr<InstanceCallback> &&callback,
64-
std::shared_ptr<MessageQueueThread> jsQueue,
65-
std::shared_ptr<MessageQueueThread> nativeQueue,
66-
std::shared_ptr<DevSettings> devSettings) noexcept;
67-
6854
std::shared_ptr<InstanceWrapper> CreateReactInstance(
6955
std::shared_ptr<Instance> &&instance,
7056
std::string &&jsBundleBasePath,
@@ -78,5 +64,4 @@ std::shared_ptr<InstanceWrapper> CreateReactInstance(
7864
std::shared_ptr<MessageQueueThread> nativeQueue,
7965
std::shared_ptr<DevSettings> devSettings) noexcept;
8066

81-
} // namespace react
82-
} // namespace facebook
67+
} // namespace facebook::react

0 commit comments

Comments
 (0)