mirror of
https://github.com/status-im/react-native.git
synced 2025-02-20 13:18:07 +00:00
Fabric: Even more systraces
Summary: Trivial. Reviewed By: mdvacca Differential Revision: D13664395 fbshipit-source-id: 3de5d65d6fcf8b68bce2636fc91492defdbe8405
This commit is contained in:
parent
aa19fa02e9
commit
8f9ca2b9a0
@ -8,6 +8,7 @@
|
||||
#import "RCTMountingManager.h"
|
||||
|
||||
#import <react/core/LayoutableShadowNode.h>
|
||||
#import <react/debug/SystraceSection.h>
|
||||
#import <React/RCTAssert.h>
|
||||
#import <React/RCTUtils.h>
|
||||
|
||||
@ -41,110 +42,116 @@ using namespace facebook::react;
|
||||
- (void)performTransactionWithMutations:(facebook::react::ShadowViewMutationList)mutations
|
||||
rootTag:(ReactTag)rootTag
|
||||
{
|
||||
NSMutableArray<RCTMountItemProtocol> *mountItems =
|
||||
[[NSMutableArray<RCTMountItemProtocol> alloc] initWithCapacity:mutations.size() * 2 /* ~ the worst case */];
|
||||
NSMutableArray<RCTMountItemProtocol> *mountItems;
|
||||
|
||||
for (const auto &mutation : mutations) {
|
||||
switch (mutation.type) {
|
||||
case ShadowViewMutation::Create: {
|
||||
RCTCreateMountItem *mountItem =
|
||||
[[RCTCreateMountItem alloc] initWithComponentHandle:mutation.newChildShadowView.componentHandle
|
||||
tag:mutation.newChildShadowView.tag];
|
||||
[mountItems addObject:mountItem];
|
||||
break;
|
||||
}
|
||||
{
|
||||
// This section is measured separately from `_performMountItems:rootTag:` because that can be asynchronous.
|
||||
SystraceSection s("-[RCTMountingManager performTransactionWithMutations:rootTag:]");
|
||||
|
||||
case ShadowViewMutation::Delete: {
|
||||
RCTDeleteMountItem *mountItem =
|
||||
[[RCTDeleteMountItem alloc] initWithComponentHandle:mutation.oldChildShadowView.componentHandle
|
||||
tag:mutation.oldChildShadowView.tag];
|
||||
[mountItems addObject:mountItem];
|
||||
break;
|
||||
}
|
||||
mountItems = [[NSMutableArray<RCTMountItemProtocol> alloc] initWithCapacity:mutations.size() * 2 /* ~ the worst case */];
|
||||
|
||||
case ShadowViewMutation::Insert: {
|
||||
// Props
|
||||
[mountItems addObject:[[RCTUpdatePropsMountItem alloc] initWithTag:mutation.newChildShadowView.tag
|
||||
oldProps:nullptr
|
||||
newProps:mutation.newChildShadowView.props]];
|
||||
|
||||
// EventEmitter
|
||||
[mountItems addObject:[[RCTUpdateEventEmitterMountItem alloc] initWithTag:mutation.newChildShadowView.tag
|
||||
eventEmitter:mutation.newChildShadowView.eventEmitter]];
|
||||
|
||||
// LocalData
|
||||
if (mutation.newChildShadowView.localData) {
|
||||
[mountItems addObject:[[RCTUpdateLocalDataMountItem alloc] initWithTag:mutation.newChildShadowView.tag
|
||||
oldLocalData:nullptr
|
||||
newLocalData:mutation.newChildShadowView.localData]];
|
||||
}
|
||||
|
||||
// Layout
|
||||
if (mutation.newChildShadowView.layoutMetrics != EmptyLayoutMetrics) {
|
||||
[mountItems addObject:[[RCTUpdateLayoutMetricsMountItem alloc] initWithTag:mutation.newChildShadowView.tag
|
||||
oldLayoutMetrics:{}
|
||||
newLayoutMetrics:mutation.newChildShadowView.layoutMetrics]];
|
||||
}
|
||||
|
||||
// Insertion
|
||||
RCTInsertMountItem *mountItem =
|
||||
[[RCTInsertMountItem alloc] initWithChildTag:mutation.newChildShadowView.tag
|
||||
parentTag:mutation.parentShadowView.tag
|
||||
index:mutation.index];
|
||||
[mountItems addObject:mountItem];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ShadowViewMutation::Remove: {
|
||||
RCTRemoveMountItem *mountItem =
|
||||
[[RCTRemoveMountItem alloc] initWithChildTag:mutation.oldChildShadowView.tag
|
||||
parentTag:mutation.parentShadowView.tag
|
||||
index:mutation.index];
|
||||
[mountItems addObject:mountItem];
|
||||
break;
|
||||
}
|
||||
|
||||
case ShadowViewMutation::Update: {
|
||||
auto oldChildShadowView = mutation.oldChildShadowView;
|
||||
auto newChildShadowView = mutation.newChildShadowView;
|
||||
|
||||
// Props
|
||||
if (oldChildShadowView.props != newChildShadowView.props) {
|
||||
RCTUpdatePropsMountItem *mountItem =
|
||||
[[RCTUpdatePropsMountItem alloc] initWithTag:mutation.oldChildShadowView.tag
|
||||
oldProps:mutation.oldChildShadowView.props
|
||||
newProps:mutation.newChildShadowView.props];
|
||||
for (const auto &mutation : mutations) {
|
||||
switch (mutation.type) {
|
||||
case ShadowViewMutation::Create: {
|
||||
RCTCreateMountItem *mountItem =
|
||||
[[RCTCreateMountItem alloc] initWithComponentHandle:mutation.newChildShadowView.componentHandle
|
||||
tag:mutation.newChildShadowView.tag];
|
||||
[mountItems addObject:mountItem];
|
||||
break;
|
||||
}
|
||||
|
||||
// EventEmitter
|
||||
if (oldChildShadowView.eventEmitter != newChildShadowView.eventEmitter) {
|
||||
RCTUpdateEventEmitterMountItem *mountItem =
|
||||
[[RCTUpdateEventEmitterMountItem alloc] initWithTag:mutation.oldChildShadowView.tag
|
||||
eventEmitter:mutation.oldChildShadowView.eventEmitter];
|
||||
case ShadowViewMutation::Delete: {
|
||||
RCTDeleteMountItem *mountItem =
|
||||
[[RCTDeleteMountItem alloc] initWithComponentHandle:mutation.oldChildShadowView.componentHandle
|
||||
tag:mutation.oldChildShadowView.tag];
|
||||
[mountItems addObject:mountItem];
|
||||
break;
|
||||
}
|
||||
|
||||
// LocalData
|
||||
if (oldChildShadowView.localData != newChildShadowView.localData) {
|
||||
RCTUpdateLocalDataMountItem *mountItem =
|
||||
[[RCTUpdateLocalDataMountItem alloc] initWithTag:newChildShadowView.tag
|
||||
oldLocalData:oldChildShadowView.localData
|
||||
newLocalData:newChildShadowView.localData];
|
||||
case ShadowViewMutation::Insert: {
|
||||
// Props
|
||||
[mountItems addObject:[[RCTUpdatePropsMountItem alloc] initWithTag:mutation.newChildShadowView.tag
|
||||
oldProps:nullptr
|
||||
newProps:mutation.newChildShadowView.props]];
|
||||
|
||||
// EventEmitter
|
||||
[mountItems addObject:[[RCTUpdateEventEmitterMountItem alloc] initWithTag:mutation.newChildShadowView.tag
|
||||
eventEmitter:mutation.newChildShadowView.eventEmitter]];
|
||||
|
||||
// LocalData
|
||||
if (mutation.newChildShadowView.localData) {
|
||||
[mountItems addObject:[[RCTUpdateLocalDataMountItem alloc] initWithTag:mutation.newChildShadowView.tag
|
||||
oldLocalData:nullptr
|
||||
newLocalData:mutation.newChildShadowView.localData]];
|
||||
}
|
||||
|
||||
// Layout
|
||||
if (mutation.newChildShadowView.layoutMetrics != EmptyLayoutMetrics) {
|
||||
[mountItems addObject:[[RCTUpdateLayoutMetricsMountItem alloc] initWithTag:mutation.newChildShadowView.tag
|
||||
oldLayoutMetrics:{}
|
||||
newLayoutMetrics:mutation.newChildShadowView.layoutMetrics]];
|
||||
}
|
||||
|
||||
// Insertion
|
||||
RCTInsertMountItem *mountItem =
|
||||
[[RCTInsertMountItem alloc] initWithChildTag:mutation.newChildShadowView.tag
|
||||
parentTag:mutation.parentShadowView.tag
|
||||
index:mutation.index];
|
||||
[mountItems addObject:mountItem];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Layout
|
||||
if (oldChildShadowView.layoutMetrics != newChildShadowView.layoutMetrics) {
|
||||
RCTUpdateLayoutMetricsMountItem *mountItem =
|
||||
[[RCTUpdateLayoutMetricsMountItem alloc] initWithTag:mutation.oldChildShadowView.tag
|
||||
oldLayoutMetrics:oldChildShadowView.layoutMetrics
|
||||
newLayoutMetrics:newChildShadowView.layoutMetrics];
|
||||
case ShadowViewMutation::Remove: {
|
||||
RCTRemoveMountItem *mountItem =
|
||||
[[RCTRemoveMountItem alloc] initWithChildTag:mutation.oldChildShadowView.tag
|
||||
parentTag:mutation.parentShadowView.tag
|
||||
index:mutation.index];
|
||||
[mountItems addObject:mountItem];
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case ShadowViewMutation::Update: {
|
||||
auto oldChildShadowView = mutation.oldChildShadowView;
|
||||
auto newChildShadowView = mutation.newChildShadowView;
|
||||
|
||||
// Props
|
||||
if (oldChildShadowView.props != newChildShadowView.props) {
|
||||
RCTUpdatePropsMountItem *mountItem =
|
||||
[[RCTUpdatePropsMountItem alloc] initWithTag:mutation.oldChildShadowView.tag
|
||||
oldProps:mutation.oldChildShadowView.props
|
||||
newProps:mutation.newChildShadowView.props];
|
||||
[mountItems addObject:mountItem];
|
||||
}
|
||||
|
||||
// EventEmitter
|
||||
if (oldChildShadowView.eventEmitter != newChildShadowView.eventEmitter) {
|
||||
RCTUpdateEventEmitterMountItem *mountItem =
|
||||
[[RCTUpdateEventEmitterMountItem alloc] initWithTag:mutation.oldChildShadowView.tag
|
||||
eventEmitter:mutation.oldChildShadowView.eventEmitter];
|
||||
[mountItems addObject:mountItem];
|
||||
}
|
||||
|
||||
// LocalData
|
||||
if (oldChildShadowView.localData != newChildShadowView.localData) {
|
||||
RCTUpdateLocalDataMountItem *mountItem =
|
||||
[[RCTUpdateLocalDataMountItem alloc] initWithTag:newChildShadowView.tag
|
||||
oldLocalData:oldChildShadowView.localData
|
||||
newLocalData:newChildShadowView.localData];
|
||||
[mountItems addObject:mountItem];
|
||||
}
|
||||
|
||||
// Layout
|
||||
if (oldChildShadowView.layoutMetrics != newChildShadowView.layoutMetrics) {
|
||||
RCTUpdateLayoutMetricsMountItem *mountItem =
|
||||
[[RCTUpdateLayoutMetricsMountItem alloc] initWithTag:mutation.oldChildShadowView.tag
|
||||
oldLayoutMetrics:oldChildShadowView.layoutMetrics
|
||||
newLayoutMetrics:newChildShadowView.layoutMetrics];
|
||||
[mountItems addObject:mountItem];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -157,6 +164,7 @@ using namespace facebook::react;
|
||||
- (void)_performMountItems:(NSArray<RCTMountItemProtocol> *)mountItems
|
||||
rootTag:(ReactTag)rootTag
|
||||
{
|
||||
SystraceSection s("-[RCTMountingManager _performMountItems:rootTag:]");
|
||||
RCTAssertMainQueue();
|
||||
|
||||
[self.delegate mountingManager:self willMountComponentsWithRootTag:rootTag];
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#import "RCTScheduler.h"
|
||||
|
||||
#import <react/debug/SystraceSection.h>
|
||||
#import <react/uimanager/ComponentDescriptorFactory.h>
|
||||
#import <react/uimanager/ContextContainer.h>
|
||||
#import <react/uimanager/Scheduler.h>
|
||||
@ -68,6 +69,8 @@ private:
|
||||
layoutConstraints:(LayoutConstraints)layoutConstraints
|
||||
layoutContext:(LayoutContext)layoutContext;
|
||||
{
|
||||
SystraceSection s("-[RCTScheduler startSurfaceWithSurfaceId:...]");
|
||||
|
||||
auto props = convertIdToFollyDynamic(initialProps);
|
||||
_scheduler->startSurface(
|
||||
surfaceId,
|
||||
@ -84,6 +87,7 @@ private:
|
||||
|
||||
- (void)stopSurfaceWithSurfaceId:(SurfaceId)surfaceId
|
||||
{
|
||||
SystraceSection s("-[RCTScheduler stopSurfaceWithSurfaceId:]");
|
||||
_scheduler->stopSurface(surfaceId);
|
||||
}
|
||||
|
||||
@ -91,6 +95,7 @@ private:
|
||||
layoutContext:(LayoutContext)layoutContext
|
||||
surfaceId:(SurfaceId)surfaceId
|
||||
{
|
||||
SystraceSection s("-[RCTScheduler measureSurfaceWithLayoutConstraints:]");
|
||||
return RCTCGSizeFromSize(_scheduler->measureSurface(surfaceId, layoutConstraints, layoutContext));
|
||||
}
|
||||
|
||||
@ -98,6 +103,7 @@ private:
|
||||
layoutContext:(LayoutContext)layoutContext
|
||||
surfaceId:(SurfaceId)surfaceId
|
||||
{
|
||||
SystraceSection s("-[RCTScheduler constraintSurfaceLayoutWithLayoutConstraints:]");
|
||||
_scheduler->constraintSurfaceLayout(surfaceId, layoutConstraints, layoutContext);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
#include <react/core/LayoutContext.h>
|
||||
#include <react/debug/SystraceSection.h>
|
||||
#include <react/uimanager/ComponentDescriptorRegistry.h>
|
||||
#include <react/uimanager/UIManager.h>
|
||||
#include <react/uimanager/UIManagerBinding.h>
|
||||
@ -68,6 +69,8 @@ void Scheduler::startSurface(
|
||||
const folly::dynamic &initialProps,
|
||||
const LayoutConstraints &layoutConstraints,
|
||||
const LayoutContext &layoutContext) const {
|
||||
SystraceSection s("Scheduler::startSurface");
|
||||
|
||||
auto shadowTree =
|
||||
std::make_unique<ShadowTree>(surfaceId, layoutConstraints, layoutContext);
|
||||
shadowTree->setDelegate(this);
|
||||
@ -85,6 +88,8 @@ void Scheduler::startSurface(
|
||||
void Scheduler::renderTemplateToSurface(
|
||||
SurfaceId surfaceId,
|
||||
const std::string &uiTemplate) {
|
||||
SystraceSection s("Scheduler::renderTemplateToSurface");
|
||||
|
||||
try {
|
||||
if (uiTemplate.size() == 0) {
|
||||
return;
|
||||
@ -109,6 +114,8 @@ void Scheduler::renderTemplateToSurface(
|
||||
}
|
||||
|
||||
void Scheduler::stopSurface(SurfaceId surfaceId) const {
|
||||
SystraceSection s("Scheduler::stopSurface");
|
||||
|
||||
shadowTreeRegistry_.visit(surfaceId, [](const ShadowTree &shadowTree) {
|
||||
// As part of stopping the Surface, we have to commit an empty tree.
|
||||
shadowTree.complete(std::const_pointer_cast<SharedShadowNodeList>(
|
||||
@ -129,6 +136,8 @@ Size Scheduler::measureSurface(
|
||||
SurfaceId surfaceId,
|
||||
const LayoutConstraints &layoutConstraints,
|
||||
const LayoutContext &layoutContext) const {
|
||||
SystraceSection s("Scheduler::measureSurface");
|
||||
|
||||
Size size;
|
||||
shadowTreeRegistry_.visit(surfaceId, [&](const ShadowTree &shadowTree) {
|
||||
size = shadowTree.measure(layoutConstraints, layoutContext);
|
||||
@ -140,6 +149,8 @@ void Scheduler::constraintSurfaceLayout(
|
||||
SurfaceId surfaceId,
|
||||
const LayoutConstraints &layoutConstraints,
|
||||
const LayoutContext &layoutContext) const {
|
||||
SystraceSection s("Scheduler::constraintSurfaceLayout");
|
||||
|
||||
shadowTreeRegistry_.visit(surfaceId, [&](const ShadowTree &shadowTree) {
|
||||
shadowTree.synchronize([&]() {
|
||||
shadowTree.constraintLayout(layoutConstraints, layoutContext);
|
||||
@ -162,6 +173,8 @@ SchedulerDelegate *Scheduler::getDelegate() const {
|
||||
void Scheduler::shadowTreeDidCommit(
|
||||
const ShadowTree &shadowTree,
|
||||
const ShadowViewMutationList &mutations) const {
|
||||
SystraceSection s("Scheduler::shadowTreeDidCommit");
|
||||
|
||||
if (delegate_) {
|
||||
delegate_->schedulerDidFinishTransaction(
|
||||
shadowTree.getSurfaceId(), mutations);
|
||||
@ -173,6 +186,8 @@ void Scheduler::shadowTreeDidCommit(
|
||||
void Scheduler::uiManagerDidFinishTransaction(
|
||||
SurfaceId surfaceId,
|
||||
const SharedShadowNodeUnsharedList &rootChildNodes) {
|
||||
SystraceSection s("Scheduler::uiManagerDidFinishTransaction");
|
||||
|
||||
shadowTreeRegistry_.visit(surfaceId, [&](const ShadowTree &shadowTree) {
|
||||
shadowTree.synchronize([&]() { shadowTree.complete(rootChildNodes); });
|
||||
});
|
||||
@ -180,6 +195,8 @@ void Scheduler::uiManagerDidFinishTransaction(
|
||||
|
||||
void Scheduler::uiManagerDidCreateShadowNode(
|
||||
const SharedShadowNode &shadowNode) {
|
||||
SystraceSection s("Scheduler::uiManagerDidCreateShadowNode");
|
||||
|
||||
if (delegate_) {
|
||||
auto layoutableShadowNode =
|
||||
dynamic_cast<const LayoutableShadowNode *>(shadowNode.get());
|
||||
|
Loading…
x
Reference in New Issue
Block a user