Skip to content

Commit

Permalink
Collapse Delete-Create mounting instructions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdvacca authored and facebook-github-bot committed Nov 3, 2019
1 parent 70904f6 commit 894ee72
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 894ee72

Please sign in to comment.