mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
StopSurface optimizations
Summary: (1) As soon as we know we can StopSurface, stop executing all mountitems by clearing out the root tag. (2) If a surface has been stopped and there's a batch of MountItems to execute against it, execute only the "delete" operations to clear views from memory. Both of these should reduce memory usage and improve speed slightly around navigation pops. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D22321389 fbshipit-source-id: 96a8292a8442528f1bba50d35208885cc4168170
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0aa8ed6361
commit
0cef464fd2
@@ -253,8 +253,8 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
|
||||
@ThreadConfined(ANY)
|
||||
@Override
|
||||
public void stopSurface(int surfaceID) {
|
||||
mBinding.stopSurface(surfaceID);
|
||||
mReactContextForRootTag.remove(surfaceID);
|
||||
mBinding.stopSurface(surfaceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -853,6 +853,7 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
|
||||
BatchMountItem batchMountItem = (BatchMountItem) mountItem;
|
||||
if (!surfaceActiveForExecution(
|
||||
batchMountItem.getRootTag(), "dispatchMountItems BatchMountItem")) {
|
||||
batchMountItem.executeDeletes(mMountingManager);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
+30
-8
@@ -45,21 +45,18 @@ public class BatchMountItem implements MountItem {
|
||||
mCommitNumber = commitNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NonNull MountingManager mountingManager) {
|
||||
private void beginMarkers(String reason) {
|
||||
Systrace.beginSection(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManager::mountViews - " + mSize + " items");
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
"FabricUIManager::" + reason + " - " + mSize + " items");
|
||||
|
||||
if (mCommitNumber > 0) {
|
||||
ReactMarker.logFabricMarker(
|
||||
ReactMarkerConstants.FABRIC_BATCH_EXECUTION_START, null, mCommitNumber);
|
||||
}
|
||||
}
|
||||
|
||||
for (int mountItemIndex = 0; mountItemIndex < mSize; mountItemIndex++) {
|
||||
MountItem mountItem = mMountItems[mountItemIndex];
|
||||
mountItem.execute(mountingManager);
|
||||
}
|
||||
|
||||
private void endMarkers() {
|
||||
if (mCommitNumber > 0) {
|
||||
ReactMarker.logFabricMarker(
|
||||
ReactMarkerConstants.FABRIC_BATCH_EXECUTION_END, null, mCommitNumber);
|
||||
@@ -68,6 +65,31 @@ public class BatchMountItem implements MountItem {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(@NonNull MountingManager mountingManager) {
|
||||
beginMarkers("mountViews");
|
||||
|
||||
for (int mountItemIndex = 0; mountItemIndex < mSize; mountItemIndex++) {
|
||||
MountItem mountItem = mMountItems[mountItemIndex];
|
||||
mountItem.execute(mountingManager);
|
||||
}
|
||||
|
||||
endMarkers();
|
||||
}
|
||||
|
||||
public void executeDeletes(@NonNull MountingManager mountingManager) {
|
||||
beginMarkers("deleteViews");
|
||||
|
||||
for (int mountItemIndex = 0; mountItemIndex < mSize; mountItemIndex++) {
|
||||
MountItem mountItem = mMountItems[mountItemIndex];
|
||||
if (mountItem instanceof RemoveDeleteMultiMountItem) {
|
||||
((RemoveDeleteMultiMountItem) mountItem).executeDeletes(mountingManager, true);
|
||||
}
|
||||
}
|
||||
|
||||
endMarkers();
|
||||
}
|
||||
|
||||
public int getRootTag() {
|
||||
return mRootTag;
|
||||
}
|
||||
|
||||
+20
-1
@@ -56,11 +56,30 @@ public class RemoveDeleteMultiMountItem implements MountItem {
|
||||
}
|
||||
|
||||
// After removing all views, delete all views marked for deletion.
|
||||
executeDeletes(mountingManager, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute only deletion operations. When being executed as part of shutdown/stopping surface,
|
||||
* deletion failures can be ignored. For example: if there is a batch of MountItems being executed
|
||||
* as part of stopSurface, a "Create" that is not executed may have a matching "Delete". The
|
||||
* Delete will fail but we can safely ignore it in those cases.
|
||||
*
|
||||
* @param mountingManager
|
||||
* @param ignoreFailures
|
||||
*/
|
||||
public void executeDeletes(@NonNull MountingManager mountingManager, boolean ignoreFailures) {
|
||||
for (int i = 0; i < mMetadata.length; i += 4) {
|
||||
int flags = mMetadata[i + FLAGS_INDEX];
|
||||
if ((flags & DELETE_FLAG) != 0) {
|
||||
int tag = mMetadata[i + TAG_INDEX];
|
||||
mountingManager.deleteView(tag);
|
||||
try {
|
||||
mountingManager.deleteView(tag);
|
||||
} catch (IllegalStateException e) {
|
||||
if (!ignoreFailures) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user