mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Collapse Delete-Create mounting instructions
Summary: This diff implements an optimization / fix in the mounting layer of Fabric Android to ignore the "deletion" and "creation" of views for the same tag in the same commit. This operation is adding ~100 ns for every commit (I measured this using a release APK running in a real device). I created a QE to enable / disable this optimization and to measure the performance impact of this change in production Changelog: Implement optimization in mounting layer of Fabric Reviewed By: JoshuaGross Differential Revision: D18279240 fbshipit-source-id: d6fdeb2a9676bcfaf47886893eed5024bf86204b
This commit is contained in:
committed by
Facebook Github Bot
parent
70904f6163
commit
894ee72278
@@ -26,6 +26,7 @@ rn_xplat_cxx_library(
|
||||
soname = "libfabricjni.$(ext)",
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
react_native_xplat_target("better:better"),
|
||||
react_native_xplat_target("config:config"),
|
||||
react_native_xplat_target("fabric/uimanager:uimanager"),
|
||||
react_native_xplat_target("fabric/components/scrollview:scrollview"),
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "ReactNativeConfigHolder.h"
|
||||
#include "StateWrapperImpl.h"
|
||||
|
||||
#import <better/set.h>
|
||||
#include <fb/fbjni.h>
|
||||
#include <jsi/JSIDynamic.h>
|
||||
#include <jsi/jsi.h>
|
||||
@@ -572,6 +573,21 @@ void Binding::schedulerDidFinishTransaction(
|
||||
auto surfaceId = mountingTransaction->getSurfaceId();
|
||||
auto &mutations = mountingTransaction->getMutations();
|
||||
|
||||
facebook::better::set<int> createAndDeleteTagsToProcess;
|
||||
if (collapseDeleteCreateMountingInstructions_) {
|
||||
for (const auto &mutation : mutations) {
|
||||
if (mutation.type == ShadowViewMutation::Delete) {
|
||||
createAndDeleteTagsToProcess.insert(mutation.oldChildShadowView.tag);
|
||||
} else if (mutation.type == ShadowViewMutation::Create) {
|
||||
int tag = mutation.oldChildShadowView.tag;
|
||||
if (createAndDeleteTagsToProcess.find(tag) != createAndDeleteTagsToProcess.end()) {
|
||||
createAndDeleteTagsToProcess.erase(tag);
|
||||
} else {
|
||||
createAndDeleteTagsToProcess.insert(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int64_t commitNumber = telemetry.getCommitNumber();
|
||||
|
||||
std::vector<local_ref<jobject>> queue;
|
||||
@@ -591,6 +607,14 @@ void Binding::schedulerDidFinishTransaction(
|
||||
for (const auto &mutation : mutations) {
|
||||
auto oldChildShadowView = mutation.oldChildShadowView;
|
||||
auto newChildShadowView = mutation.newChildShadowView;
|
||||
auto mutationType = mutation.type;
|
||||
|
||||
if (collapseDeleteCreateMountingInstructions_ &&
|
||||
(mutationType == ShadowViewMutation::Create || mutationType == ShadowViewMutation::Delete) &&
|
||||
createAndDeleteTagsToProcess.size() > 0 &&
|
||||
createAndDeleteTagsToProcess.find(mutation.newChildShadowView.tag) == createAndDeleteTagsToProcess.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool isVirtual = newChildShadowView.layoutMetrics == EmptyLayoutMetrics &&
|
||||
oldChildShadowView.layoutMetrics == EmptyLayoutMetrics;
|
||||
|
||||
Reference in New Issue
Block a user