mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Avoid copying surface props when starting or updating a surface (#57813)
Summary: Pull Request resolved: https://github.com/react/react-native/pull/57813 `SurfaceHandler` already takes a throwaway snapshot of its `Parameters` under `parametersMutex_` before handing them to the `UIManager`, but `UIManager::startSurface` and `UIManager::setSurfaceProps` took `moduleName` and `props` by const reference and then copy-captured them into the lambda posted to the `RuntimeExecutor`. That forced a second deep copy of the props tree — which for a real surface holds the initial route params and deep link data — on every surface start, prop update, and display mode change. Take both by value and move them into the lambda, and move at the `SurfaceHandler` call sites, so the snapshot is handed off instead of duplicated. The snapshot is a local that is dead after the call, so there is nothing left to observe the moved-from state. Changelog: [General][Changed] - `UIManager::startSurface` and `UIManager::setSurfaceProps` now take `moduleName` and `props` by value Reviewed By: zeyap, christophpurrer Differential Revision: D114730310 fbshipit-source-id: 7891f6ac61abda43ff0da5f4336741af6c329ed2
This commit is contained in:
1 parent
1492a6080f
commit
85a81818c6
12 files changed
+40
-37
No files matched your search
@@ -64,8 +64,8 @@ void SurfaceHandler::start() const noexcept {
|
||||
if (!parameters.moduleName.empty()) {
|
||||
link_.uiManager->startSurface(
|
||||
std::move(shadowTree),
|
||||
parameters.moduleName,
|
||||
parameters.props,
|
||||
std::move(parameters.moduleName),
|
||||
std::move(parameters.props),
|
||||
parameters_.displayMode);
|
||||
} else {
|
||||
link_.uiManager->startEmptySurface(std::move(shadowTree));
|
||||
@@ -118,8 +118,8 @@ void SurfaceHandler::setDisplayMode(DisplayMode displayMode) const noexcept {
|
||||
|
||||
link_.uiManager->setSurfaceProps(
|
||||
parameters.surfaceId,
|
||||
parameters.moduleName,
|
||||
parameters.props,
|
||||
std::move(parameters.moduleName),
|
||||
std::move(parameters.props),
|
||||
parameters.displayMode);
|
||||
|
||||
applyDisplayMode(displayMode);
|
||||
@@ -164,8 +164,8 @@ void SurfaceHandler::setProps(const folly::dynamic& props) const noexcept {
|
||||
if (link_.status == Status::Running) {
|
||||
link_.uiManager->setSurfaceProps(
|
||||
parameters.surfaceId,
|
||||
parameters.moduleName,
|
||||
parameters.props,
|
||||
std::move(parameters.moduleName),
|
||||
std::move(parameters.props),
|
||||
parameters.displayMode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,8 +234,8 @@ void UIManager::setIsJSResponder(
|
||||
|
||||
void UIManager::startSurface(
|
||||
ShadowTree::Unique&& shadowTree,
|
||||
const std::string& moduleName,
|
||||
const folly::dynamic& props,
|
||||
std::string moduleName,
|
||||
folly::dynamic props,
|
||||
DisplayMode displayMode) const noexcept {
|
||||
TraceSection s("UIManager::startSurface");
|
||||
|
||||
@@ -249,7 +249,10 @@ void UIManager::startSurface(
|
||||
}
|
||||
});
|
||||
|
||||
runtimeExecutor_([=](jsi::Runtime& runtime) {
|
||||
runtimeExecutor_([surfaceId,
|
||||
moduleName = std::move(moduleName),
|
||||
props = std::move(props),
|
||||
displayMode](jsi::Runtime& runtime) {
|
||||
TraceSection s("UIManager::startSurface::onRuntime");
|
||||
AppRegistryBinding::startSurface(
|
||||
runtime, surfaceId, moduleName, props, displayMode);
|
||||
@@ -264,12 +267,15 @@ void UIManager::startEmptySurface(
|
||||
|
||||
void UIManager::setSurfaceProps(
|
||||
SurfaceId surfaceId,
|
||||
const std::string& moduleName,
|
||||
const folly::dynamic& props,
|
||||
std::string moduleName,
|
||||
folly::dynamic props,
|
||||
DisplayMode displayMode) const noexcept {
|
||||
TraceSection s("UIManager::setSurfaceProps");
|
||||
|
||||
runtimeExecutor_([=](jsi::Runtime& runtime) {
|
||||
runtimeExecutor_([surfaceId,
|
||||
moduleName = std::move(moduleName),
|
||||
props = std::move(props),
|
||||
displayMode](jsi::Runtime& runtime) {
|
||||
AppRegistryBinding::setSurfaceProps(
|
||||
runtime, surfaceId, moduleName, props, displayMode);
|
||||
});
|
||||
|
||||
@@ -116,17 +116,14 @@ class UIManager final : public ShadowTreeDelegate {
|
||||
|
||||
void startSurface(
|
||||
ShadowTree::Unique &&shadowTree,
|
||||
const std::string &moduleName,
|
||||
const folly::dynamic &props,
|
||||
std::string moduleName,
|
||||
folly::dynamic props,
|
||||
DisplayMode displayMode) const noexcept;
|
||||
|
||||
void startEmptySurface(ShadowTree::Unique &&shadowTree) const noexcept;
|
||||
|
||||
void setSurfaceProps(
|
||||
SurfaceId surfaceId,
|
||||
const std::string &moduleName,
|
||||
const folly::dynamic &props,
|
||||
DisplayMode displayMode) const noexcept;
|
||||
void setSurfaceProps(SurfaceId surfaceId, std::string moduleName, folly::dynamic props, DisplayMode displayMode)
|
||||
const noexcept;
|
||||
|
||||
ShadowTree::Unique stopSurface(SurfaceId surfaceId) const;
|
||||
|
||||
|
||||
@@ -5295,10 +5295,10 @@ class facebook::react::UIManager : public facebook::react::ShadowTreeDelegate {
|
||||
public void setDelegate(facebook::react::UIManagerDelegate* delegate);
|
||||
public void setIsJSResponder(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, bool isJSResponder, bool blockNativeResponder) const;
|
||||
public void setNativeAnimatedDelegate(std::weak_ptr<facebook::react::UIManagerNativeAnimatedDelegate> delegate);
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setViewTransitionDelegate(facebook::react::UIManagerViewTransitionDelegate* delegate);
|
||||
public void startEmptySurface(facebook::react::ShadowTree::Unique&& shadowTree) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void stopSurfaceForAnimationDelegate(facebook::react::SurfaceId surfaceId) const;
|
||||
public void synchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props);
|
||||
public void unregisterCommitHook(facebook::react::UIManagerCommitHook& commitHook);
|
||||
|
||||
@@ -5106,10 +5106,10 @@ class facebook::react::UIManager : public facebook::react::ShadowTreeDelegate {
|
||||
public void setDelegate(facebook::react::UIManagerDelegate* delegate);
|
||||
public void setIsJSResponder(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, bool isJSResponder, bool blockNativeResponder) const;
|
||||
public void setNativeAnimatedDelegate(std::weak_ptr<facebook::react::UIManagerNativeAnimatedDelegate> delegate);
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setViewTransitionDelegate(facebook::react::UIManagerViewTransitionDelegate* delegate);
|
||||
public void startEmptySurface(facebook::react::ShadowTree::Unique&& shadowTree) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void stopSurfaceForAnimationDelegate(facebook::react::SurfaceId surfaceId) const;
|
||||
public void synchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props);
|
||||
public void unregisterCommitHook(facebook::react::UIManagerCommitHook& commitHook);
|
||||
|
||||
@@ -5286,10 +5286,10 @@ class facebook::react::UIManager : public facebook::react::ShadowTreeDelegate {
|
||||
public void setDelegate(facebook::react::UIManagerDelegate* delegate);
|
||||
public void setIsJSResponder(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, bool isJSResponder, bool blockNativeResponder) const;
|
||||
public void setNativeAnimatedDelegate(std::weak_ptr<facebook::react::UIManagerNativeAnimatedDelegate> delegate);
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setViewTransitionDelegate(facebook::react::UIManagerViewTransitionDelegate* delegate);
|
||||
public void startEmptySurface(facebook::react::ShadowTree::Unique&& shadowTree) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void stopSurfaceForAnimationDelegate(facebook::react::SurfaceId surfaceId) const;
|
||||
public void synchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props);
|
||||
public void unregisterCommitHook(facebook::react::UIManagerCommitHook& commitHook);
|
||||
|
||||
@@ -7471,10 +7471,10 @@ class facebook::react::UIManager : public facebook::react::ShadowTreeDelegate {
|
||||
public void setDelegate(facebook::react::UIManagerDelegate* delegate);
|
||||
public void setIsJSResponder(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, bool isJSResponder, bool blockNativeResponder) const;
|
||||
public void setNativeAnimatedDelegate(std::weak_ptr<facebook::react::UIManagerNativeAnimatedDelegate> delegate);
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setViewTransitionDelegate(facebook::react::UIManagerViewTransitionDelegate* delegate);
|
||||
public void startEmptySurface(facebook::react::ShadowTree::Unique&& shadowTree) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void stopSurfaceForAnimationDelegate(facebook::react::SurfaceId surfaceId) const;
|
||||
public void synchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props);
|
||||
public void unregisterCommitHook(facebook::react::UIManagerCommitHook& commitHook);
|
||||
|
||||
@@ -7310,10 +7310,10 @@ class facebook::react::UIManager : public facebook::react::ShadowTreeDelegate {
|
||||
public void setDelegate(facebook::react::UIManagerDelegate* delegate);
|
||||
public void setIsJSResponder(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, bool isJSResponder, bool blockNativeResponder) const;
|
||||
public void setNativeAnimatedDelegate(std::weak_ptr<facebook::react::UIManagerNativeAnimatedDelegate> delegate);
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setViewTransitionDelegate(facebook::react::UIManagerViewTransitionDelegate* delegate);
|
||||
public void startEmptySurface(facebook::react::ShadowTree::Unique&& shadowTree) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void stopSurfaceForAnimationDelegate(facebook::react::SurfaceId surfaceId) const;
|
||||
public void synchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props);
|
||||
public void unregisterCommitHook(facebook::react::UIManagerCommitHook& commitHook);
|
||||
|
||||
@@ -7462,10 +7462,10 @@ class facebook::react::UIManager : public facebook::react::ShadowTreeDelegate {
|
||||
public void setDelegate(facebook::react::UIManagerDelegate* delegate);
|
||||
public void setIsJSResponder(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, bool isJSResponder, bool blockNativeResponder) const;
|
||||
public void setNativeAnimatedDelegate(std::weak_ptr<facebook::react::UIManagerNativeAnimatedDelegate> delegate);
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setViewTransitionDelegate(facebook::react::UIManagerViewTransitionDelegate* delegate);
|
||||
public void startEmptySurface(facebook::react::ShadowTree::Unique&& shadowTree) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void stopSurfaceForAnimationDelegate(facebook::react::SurfaceId surfaceId) const;
|
||||
public void synchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props);
|
||||
public void unregisterCommitHook(facebook::react::UIManagerCommitHook& commitHook);
|
||||
|
||||
@@ -3746,10 +3746,10 @@ class facebook::react::UIManager : public facebook::react::ShadowTreeDelegate {
|
||||
public void setDelegate(facebook::react::UIManagerDelegate* delegate);
|
||||
public void setIsJSResponder(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, bool isJSResponder, bool blockNativeResponder) const;
|
||||
public void setNativeAnimatedDelegate(std::weak_ptr<facebook::react::UIManagerNativeAnimatedDelegate> delegate);
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setViewTransitionDelegate(facebook::react::UIManagerViewTransitionDelegate* delegate);
|
||||
public void startEmptySurface(facebook::react::ShadowTree::Unique&& shadowTree) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void stopSurfaceForAnimationDelegate(facebook::react::SurfaceId surfaceId) const;
|
||||
public void synchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props);
|
||||
public void unregisterCommitHook(facebook::react::UIManagerCommitHook& commitHook);
|
||||
|
||||
@@ -3597,10 +3597,10 @@ class facebook::react::UIManager : public facebook::react::ShadowTreeDelegate {
|
||||
public void setDelegate(facebook::react::UIManagerDelegate* delegate);
|
||||
public void setIsJSResponder(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, bool isJSResponder, bool blockNativeResponder) const;
|
||||
public void setNativeAnimatedDelegate(std::weak_ptr<facebook::react::UIManagerNativeAnimatedDelegate> delegate);
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setViewTransitionDelegate(facebook::react::UIManagerViewTransitionDelegate* delegate);
|
||||
public void startEmptySurface(facebook::react::ShadowTree::Unique&& shadowTree) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void stopSurfaceForAnimationDelegate(facebook::react::SurfaceId surfaceId) const;
|
||||
public void synchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props);
|
||||
public void unregisterCommitHook(facebook::react::UIManagerCommitHook& commitHook);
|
||||
|
||||
@@ -3737,10 +3737,10 @@ class facebook::react::UIManager : public facebook::react::ShadowTreeDelegate {
|
||||
public void setDelegate(facebook::react::UIManagerDelegate* delegate);
|
||||
public void setIsJSResponder(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, bool isJSResponder, bool blockNativeResponder) const;
|
||||
public void setNativeAnimatedDelegate(std::weak_ptr<facebook::react::UIManagerNativeAnimatedDelegate> delegate);
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setSurfaceProps(facebook::react::SurfaceId surfaceId, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void setViewTransitionDelegate(facebook::react::UIManagerViewTransitionDelegate* delegate);
|
||||
public void startEmptySurface(facebook::react::ShadowTree::Unique&& shadowTree) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, const std::string& moduleName, const folly::dynamic& props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void startSurface(facebook::react::ShadowTree::Unique&& shadowTree, std::string moduleName, folly::dynamic props, facebook::react::DisplayMode displayMode) const noexcept;
|
||||
public void stopSurfaceForAnimationDelegate(facebook::react::SurfaceId surfaceId) const;
|
||||
public void synchronouslyUpdateViewOnUIThread(facebook::react::Tag tag, const folly::dynamic& props);
|
||||
public void unregisterCommitHook(facebook::react::UIManagerCommitHook& commitHook);
|
||||
|
||||
Reference in new issue
Block a user