Recycle CSSNodes

Summary: Adds a pool to recycle CSSNodes within UIManager. A follow-up diff will hook this up to a memory pressure listener to drop the pool on memory pressure.

Reviewed By: emilsjolander

Differential Revision: D4189532

fbshipit-source-id: 46583546f71a8c59853e1dd124de31657b3c617b
This commit is contained in:
Andy Street
2016-11-21 09:11:29 -08:00
committed by Facebook Github Bot
parent 7c91f894ba
commit bd8745b1fd
5 changed files with 107 additions and 10 deletions

View File

@@ -74,7 +74,15 @@ public class ReactShadowNode {
private float mAbsoluteBottom;
private final Spacing mDefaultPadding = new Spacing(0);
private final Spacing mPadding = new Spacing(CSSConstants.UNDEFINED);
private final CSSNode mCSSNode = new CSSNode();
private final CSSNode mCSSNode;
public ReactShadowNode() {
CSSNode node = CSSNodePool.get().acquire();
if (node == null) {
node = new CSSNode();
}
mCSSNode = node;
}
/**
* Nodes that return {@code true} will be treated as "virtual" nodes. That is, nodes that are not
@@ -190,7 +198,7 @@ public class ReactShadowNode {
return mChildren == null ? -1 : mChildren.indexOf(child);
}
public void removeAllChildren() {
public void removeAndDisposeAllChildren() {
if (getChildCount() == 0) {
return;
}
@@ -202,6 +210,8 @@ public class ReactShadowNode {
}
ReactShadowNode toRemove = getChildAt(i);
toRemove.mParent = null;
toRemove.dispose();
decrease += toRemove.mIsLayoutOnly ? toRemove.mTotalNativeChildren : 1;
}
Assertions.assertNotNull(mChildren).clear();
@@ -654,4 +664,9 @@ public class ReactShadowNode {
public String toString() {
return mCSSNode.toString();
}
public void dispose() {
mCSSNode.reset();
CSSNodePool.get().release(mCSSNode);
}
}