mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Only use State Reconciliation during certain commits from ReactJS, not during State commits or others
Summary: Only use State Reconciliation during certain commits from ReactJS, not during State commits or others The idea is that this will have better perf, since many types of commits don't need State Reconciliation at all. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D19794999 fbshipit-source-id: 336325f225d993a6aae9f55cb95a7a2b38a6d853
This commit is contained in:
1 parent
27981ad991
commit
c525ab5e04
5 files changed
+50
-20
No files matched your search
@@ -129,14 +129,16 @@ MountingCoordinator::Shared ShadowTree::getMountingCoordinator() const {
|
||||
return mountingCoordinator_;
|
||||
}
|
||||
|
||||
void ShadowTree::commit(ShadowTreeCommitTransaction transaction) const {
|
||||
void ShadowTree::commit(
|
||||
ShadowTreeCommitTransaction transaction,
|
||||
bool enableStateReconciliation) const {
|
||||
SystraceSection s("ShadowTree::commit");
|
||||
|
||||
int attempts = 0;
|
||||
|
||||
while (true) {
|
||||
attempts++;
|
||||
if (tryCommit(transaction)) {
|
||||
if (tryCommit(transaction, enableStateReconciliation)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -146,7 +148,9 @@ void ShadowTree::commit(ShadowTreeCommitTransaction transaction) const {
|
||||
}
|
||||
}
|
||||
|
||||
bool ShadowTree::tryCommit(ShadowTreeCommitTransaction transaction) const {
|
||||
bool ShadowTree::tryCommit(
|
||||
ShadowTreeCommitTransaction transaction,
|
||||
bool enableStateReconciliation) const {
|
||||
SystraceSection s("ShadowTree::tryCommit");
|
||||
|
||||
auto telemetry = MountingTelemetry{};
|
||||
@@ -168,11 +172,13 @@ bool ShadowTree::tryCommit(ShadowTreeCommitTransaction transaction) const {
|
||||
|
||||
// Compare state revisions of old and new root
|
||||
// Children of the root node may be mutated in-place
|
||||
UnsharedShadowNode reconciledNode =
|
||||
reconcileStateWithTree(newRootShadowNode.get(), oldRootShadowNode);
|
||||
if (reconciledNode != nullptr) {
|
||||
newRootShadowNode =
|
||||
std::make_shared<RootShadowNode>(*reconciledNode, ShadowNodeFragment{});
|
||||
if (enableStateReconciliation) {
|
||||
UnsharedShadowNode reconciledNode =
|
||||
reconcileStateWithTree(newRootShadowNode.get(), oldRootShadowNode);
|
||||
if (reconciledNode != nullptr) {
|
||||
newRootShadowNode = std::make_shared<RootShadowNode>(
|
||||
*reconciledNode, ShadowNodeFragment{});
|
||||
}
|
||||
}
|
||||
|
||||
// Layout nodes
|
||||
|
||||
@@ -53,12 +53,16 @@ class ShadowTree final {
|
||||
* The `transaction` function can abort commit returning `nullptr`.
|
||||
* Returns `true` if the operation finished successfully.
|
||||
*/
|
||||
bool tryCommit(ShadowTreeCommitTransaction transaction) const;
|
||||
bool tryCommit(
|
||||
ShadowTreeCommitTransaction transaction,
|
||||
bool enableStateReconciliation = false) const;
|
||||
|
||||
/*
|
||||
* Calls `tryCommit` in a loop until it finishes successfully.
|
||||
*/
|
||||
void commit(ShadowTreeCommitTransaction transaction) const;
|
||||
void commit(
|
||||
ShadowTreeCommitTransaction transaction,
|
||||
bool enableStateReconciliation = false) const;
|
||||
|
||||
/*
|
||||
* Commit an empty tree (a new `RootShadowNode` with no children).
|
||||
|
||||
@@ -67,6 +67,15 @@ Scheduler::Scheduler(
|
||||
uiManager->setDelegate(this);
|
||||
uiManager->setComponentDescriptorRegistry(componentDescriptorRegistry_);
|
||||
|
||||
#ifdef ANDROID
|
||||
bool stateReconciliationEnabled = reactNativeConfig_->getBool(
|
||||
"react_fabric:enabled_state_reconciliation_android");
|
||||
#else
|
||||
bool stateReconciliationEnabled = reactNativeConfig_->getBool(
|
||||
"react_fabric:enabled_state_reconciliation_ios");
|
||||
#endif
|
||||
uiManager->setStateReconciliationEnabled(stateReconciliationEnabled);
|
||||
|
||||
runtimeExecutor_([=](jsi::Runtime &runtime) {
|
||||
auto uiManagerBinding = UIManagerBinding::createAndInstallIfNeeded(runtime);
|
||||
uiManagerBinding->attach(uiManager);
|
||||
|
||||
@@ -109,17 +109,23 @@ void UIManager::completeSurface(
|
||||
SystraceSection s("UIManager::completeSurface");
|
||||
|
||||
shadowTreeRegistry_.visit(surfaceId, [&](ShadowTree const &shadowTree) {
|
||||
shadowTree.commit([&](RootShadowNode::Shared const &oldRootShadowNode) {
|
||||
return std::make_shared<RootShadowNode>(
|
||||
*oldRootShadowNode,
|
||||
ShadowNodeFragment{
|
||||
/* .props = */ ShadowNodeFragment::propsPlaceholder(),
|
||||
/* .children = */ rootChildren,
|
||||
});
|
||||
});
|
||||
shadowTree.commit(
|
||||
[&](RootShadowNode::Shared const &oldRootShadowNode) {
|
||||
return std::make_shared<RootShadowNode>(
|
||||
*oldRootShadowNode,
|
||||
ShadowNodeFragment{
|
||||
/* .props = */ ShadowNodeFragment::propsPlaceholder(),
|
||||
/* .children = */ rootChildren,
|
||||
});
|
||||
},
|
||||
true && stateReconciliationEnabled_);
|
||||
});
|
||||
}
|
||||
|
||||
void UIManager::setStateReconciliationEnabled(bool enabled) {
|
||||
stateReconciliationEnabled_ = enabled;
|
||||
}
|
||||
|
||||
void UIManager::setJSResponder(
|
||||
const ShadowNode::Shared &shadowNode,
|
||||
const bool blockNativeResponder) const {
|
||||
@@ -159,7 +165,8 @@ void UIManager::setNativeProps(
|
||||
/* .props = */ props,
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
true && stateReconciliationEnabled_);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -176,7 +183,8 @@ LayoutMetrics UIManager::getRelativeLayoutMetrics(
|
||||
[&](RootShadowNode::Shared const &oldRootShadowNode) {
|
||||
ancestorShadowNode = oldRootShadowNode.get();
|
||||
return nullptr;
|
||||
});
|
||||
},
|
||||
true && stateReconciliationEnabled_);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@ class UIManager final : public ShadowTreeDelegate {
|
||||
ShadowTree const &shadowTree,
|
||||
MountingCoordinator::Shared const &mountingCoordinator) const override;
|
||||
|
||||
void setStateReconciliationEnabled(bool enabled);
|
||||
|
||||
private:
|
||||
friend class UIManagerBinding;
|
||||
friend class Scheduler;
|
||||
@@ -121,6 +123,7 @@ class UIManager final : public ShadowTreeDelegate {
|
||||
UIManagerDelegate *delegate_;
|
||||
UIManagerBinding *uiManagerBinding_;
|
||||
ShadowTreeRegistry shadowTreeRegistry_{};
|
||||
bool stateReconciliationEnabled_{false};
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
||||
Reference in new issue
Block a user