Remove isTextNode optimization
Summary: Scrolling through feed and logging when this optimization is hit leads to... 0 logs. If anything this just adds to confusion. It was initially added due to instinct and not data, which was a mistake. I am happy to add some similar optimization in the future if we have data that it is useful in real world situations, currently it just leads to bugs and confusion though. Reviewed By: astreet Differential Revision: D4146785 fbshipit-source-id: e20d780fbd5759b8f38b809e8cadf29cedee82a8
This commit is contained in:
committed by
Facebook Github Bot
parent
b50090a04e
commit
1baa239389
@@ -89,7 +89,6 @@ typedef struct CSSNode {
|
|||||||
CSSLayout layout;
|
CSSLayout layout;
|
||||||
uint32_t lineIndex;
|
uint32_t lineIndex;
|
||||||
bool hasNewLayout;
|
bool hasNewLayout;
|
||||||
bool isTextNode;
|
|
||||||
CSSNodeRef parent;
|
CSSNodeRef parent;
|
||||||
CSSNodeListRef children;
|
CSSNodeListRef children;
|
||||||
bool isDirty;
|
bool isDirty;
|
||||||
@@ -382,7 +381,6 @@ void CSSNodeStyleSetFlex(const CSSNodeRef node, const float flex) {
|
|||||||
|
|
||||||
CSS_NODE_PROPERTY_IMPL(void *, Context, context, context);
|
CSS_NODE_PROPERTY_IMPL(void *, Context, context, context);
|
||||||
CSS_NODE_PROPERTY_IMPL(CSSPrintFunc, PrintFunc, printFunc, print);
|
CSS_NODE_PROPERTY_IMPL(CSSPrintFunc, PrintFunc, printFunc, print);
|
||||||
CSS_NODE_PROPERTY_IMPL(bool, IsTextnode, isTextNode, isTextNode);
|
|
||||||
CSS_NODE_PROPERTY_IMPL(bool, HasNewLayout, hasNewLayout, hasNewLayout);
|
CSS_NODE_PROPERTY_IMPL(bool, HasNewLayout, hasNewLayout, hasNewLayout);
|
||||||
|
|
||||||
CSS_NODE_STYLE_PROPERTY_IMPL(CSSDirection, Direction, direction, direction);
|
CSS_NODE_STYLE_PROPERTY_IMPL(CSSDirection, Direction, direction, direction);
|
||||||
@@ -2104,8 +2102,7 @@ static inline bool newMeasureSizeIsStricterAndStillValid(CSSMeasureMode sizeMode
|
|||||||
lastSize > size && lastComputedSize <= size;
|
lastSize > size && lastComputedSize <= size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSSNodeCanUseCachedMeasurement(const bool isTextNode,
|
bool CSSNodeCanUseCachedMeasurement(const CSSMeasureMode widthMode,
|
||||||
const CSSMeasureMode widthMode,
|
|
||||||
const float width,
|
const float width,
|
||||||
const CSSMeasureMode heightMode,
|
const CSSMeasureMode heightMode,
|
||||||
const float height,
|
const float height,
|
||||||
@@ -2134,7 +2131,7 @@ bool CSSNodeCanUseCachedMeasurement(const bool isTextNode,
|
|||||||
newMeasureSizeIsStricterAndStillValid(
|
newMeasureSizeIsStricterAndStillValid(
|
||||||
widthMode, width - marginRow, lastWidthMode, lastWidth, lastComputedWidth);
|
widthMode, width - marginRow, lastWidthMode, lastWidth, lastComputedWidth);
|
||||||
|
|
||||||
const bool heightIsCompatible = isTextNode || hasSameHeightSpec ||
|
const bool heightIsCompatible = hasSameHeightSpec ||
|
||||||
newSizeIsExactAndMatchesOldMeasuredSize(heightMode,
|
newSizeIsExactAndMatchesOldMeasuredSize(heightMode,
|
||||||
height - marginColumn,
|
height - marginColumn,
|
||||||
lastComputedHeight) ||
|
lastComputedHeight) ||
|
||||||
@@ -2203,8 +2200,7 @@ bool layoutNodeInternal(const CSSNodeRef node,
|
|||||||
const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn);
|
const float marginAxisColumn = getMarginAxis(node, CSSFlexDirectionColumn);
|
||||||
|
|
||||||
// First, try to use the layout cache.
|
// First, try to use the layout cache.
|
||||||
if (CSSNodeCanUseCachedMeasurement(node->isTextNode,
|
if (CSSNodeCanUseCachedMeasurement(widthMeasureMode,
|
||||||
widthMeasureMode,
|
|
||||||
availableWidth,
|
availableWidth,
|
||||||
heightMeasureMode,
|
heightMeasureMode,
|
||||||
availableHeight,
|
availableHeight,
|
||||||
@@ -2220,8 +2216,7 @@ bool layoutNodeInternal(const CSSNodeRef node,
|
|||||||
} else {
|
} else {
|
||||||
// Try to use the measurement cache.
|
// Try to use the measurement cache.
|
||||||
for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
|
for (uint32_t i = 0; i < layout->nextCachedMeasurementsIndex; i++) {
|
||||||
if (CSSNodeCanUseCachedMeasurement(node->isTextNode,
|
if (CSSNodeCanUseCachedMeasurement(widthMeasureMode,
|
||||||
widthMeasureMode,
|
|
||||||
availableWidth,
|
availableWidth,
|
||||||
heightMeasureMode,
|
heightMeasureMode,
|
||||||
availableHeight,
|
availableHeight,
|
||||||
|
@@ -161,8 +161,7 @@ WIN_EXPORT void CSSNodePrint(const CSSNodeRef node, const CSSPrintOptions option
|
|||||||
|
|
||||||
WIN_EXPORT bool CSSValueIsUndefined(const float value);
|
WIN_EXPORT bool CSSValueIsUndefined(const float value);
|
||||||
|
|
||||||
WIN_EXPORT bool CSSNodeCanUseCachedMeasurement(const bool isTextNode,
|
WIN_EXPORT bool CSSNodeCanUseCachedMeasurement(const CSSMeasureMode widthMode,
|
||||||
const CSSMeasureMode widthMode,
|
|
||||||
const float width,
|
const float width,
|
||||||
const CSSMeasureMode heightMode,
|
const CSSMeasureMode heightMode,
|
||||||
const float height,
|
const float height,
|
||||||
@@ -195,7 +194,6 @@ WIN_EXPORT bool CSSNodeCanUseCachedMeasurement(const bool isTextNode,
|
|||||||
CSS_NODE_PROPERTY(void *, Context, context);
|
CSS_NODE_PROPERTY(void *, Context, context);
|
||||||
CSS_NODE_PROPERTY(CSSMeasureFunc, MeasureFunc, measureFunc);
|
CSS_NODE_PROPERTY(CSSMeasureFunc, MeasureFunc, measureFunc);
|
||||||
CSS_NODE_PROPERTY(CSSPrintFunc, PrintFunc, printFunc);
|
CSS_NODE_PROPERTY(CSSPrintFunc, PrintFunc, printFunc);
|
||||||
CSS_NODE_PROPERTY(bool, IsTextnode, isTextNode);
|
|
||||||
CSS_NODE_PROPERTY(bool, HasNewLayout, hasNewLayout);
|
CSS_NODE_PROPERTY(bool, HasNewLayout, hasNewLayout);
|
||||||
|
|
||||||
CSS_NODE_STYLE_PROPERTY(CSSDirection, Direction, direction);
|
CSS_NODE_STYLE_PROPERTY(CSSDirection, Direction, direction);
|
||||||
|
@@ -62,19 +62,6 @@ namespace Facebook.CSSLayout
|
|||||||
Native.CSSNodeMarkDirty(_cssNode);
|
Native.CSSNodeMarkDirty(_cssNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsTextNode
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return Native.CSSNodeGetIsTextnode(_cssNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
Native.CSSNodeSetIsTextnode(_cssNode, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HasNewLayout
|
public bool HasNewLayout
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@@ -92,13 +92,6 @@ namespace Facebook.CSSLayout
|
|||||||
[return: MarshalAs(UnmanagedType.FunctionPtr)]
|
[return: MarshalAs(UnmanagedType.FunctionPtr)]
|
||||||
public static extern CSSMeasureFunc CSSNodeGetMeasureFunc(IntPtr node);
|
public static extern CSSMeasureFunc CSSNodeGetMeasureFunc(IntPtr node);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
|
||||||
public static extern void CSSNodeSetIsTextnode(IntPtr node, [MarshalAs(UnmanagedType.I1)] bool isTextNode);
|
|
||||||
|
|
||||||
[DllImport(DllName)]
|
|
||||||
[return: MarshalAs(UnmanagedType.I1)]
|
|
||||||
public static extern bool CSSNodeGetIsTextnode(IntPtr node);
|
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void CSSNodeSetHasNewLayout(IntPtr node, [MarshalAs(UnmanagedType.I1)] bool hasNewLayout);
|
public static extern void CSSNodeSetHasNewLayout(IntPtr node, [MarshalAs(UnmanagedType.I1)] bool hasNewLayout);
|
||||||
|
|
||||||
|
@@ -140,18 +140,6 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
|
|||||||
return mChildren == null ? -1 : mChildren.indexOf(child);
|
return mChildren == null ? -1 : mChildren.indexOf(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
private native void jni_CSSNodeSetIsTextNode(long nativePointer, boolean isTextNode);
|
|
||||||
@Override
|
|
||||||
public void setIsTextNode(boolean isTextNode) {
|
|
||||||
jni_CSSNodeSetIsTextNode(mNativePointer, isTextNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
private native boolean jni_CSSNodeGetIsTextNode(long nativePointer);
|
|
||||||
@Override
|
|
||||||
public boolean isTextNode() {
|
|
||||||
return jni_CSSNodeGetIsTextNode(mNativePointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private native void jni_CSSNodeCalculateLayout(long nativePointer);
|
private native void jni_CSSNodeCalculateLayout(long nativePointer);
|
||||||
@Override
|
@Override
|
||||||
public void calculateLayout(CSSLayoutContext layoutContext) {
|
public void calculateLayout(CSSLayoutContext layoutContext) {
|
||||||
|
@@ -31,8 +31,6 @@ public interface CSSNodeAPI<CSSNodeType extends CSSNodeAPI> {
|
|||||||
int indexOf(CSSNodeType child);
|
int indexOf(CSSNodeType child);
|
||||||
void setMeasureFunction(MeasureFunction measureFunction);
|
void setMeasureFunction(MeasureFunction measureFunction);
|
||||||
boolean isMeasureDefined();
|
boolean isMeasureDefined();
|
||||||
void setIsTextNode(boolean isTextNode);
|
|
||||||
boolean isTextNode();
|
|
||||||
void calculateLayout(CSSLayoutContext layoutContext);
|
void calculateLayout(CSSLayoutContext layoutContext);
|
||||||
boolean isDirty();
|
boolean isDirty();
|
||||||
boolean hasNewLayout();
|
boolean hasNewLayout();
|
||||||
|
@@ -58,7 +58,6 @@ public class CSSNodeDEPRECATED implements CSSNodeAPI<CSSNodeDEPRECATED> {
|
|||||||
private @Nullable CSSNodeDEPRECATED mParent;
|
private @Nullable CSSNodeDEPRECATED mParent;
|
||||||
private @Nullable MeasureFunction mMeasureFunction = null;
|
private @Nullable MeasureFunction mMeasureFunction = null;
|
||||||
private LayoutState mLayoutState = LayoutState.DIRTY;
|
private LayoutState mLayoutState = LayoutState.DIRTY;
|
||||||
private boolean mIsTextNode = false;
|
|
||||||
private Object mData;
|
private Object mData;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -124,16 +123,6 @@ public class CSSNodeDEPRECATED implements CSSNodeAPI<CSSNodeDEPRECATED> {
|
|||||||
return mMeasureFunction != null;
|
return mMeasureFunction != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setIsTextNode(boolean isTextNode) {
|
|
||||||
mIsTextNode = isTextNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isTextNode() {
|
|
||||||
return mIsTextNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
long measure(float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode) {
|
long measure(float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode) {
|
||||||
if (!isMeasureDefined()) {
|
if (!isMeasureDefined()) {
|
||||||
throw new RuntimeException("Measure function isn't defined!");
|
throw new RuntimeException("Measure function isn't defined!");
|
||||||
|
@@ -240,7 +240,6 @@ public class LayoutEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ static boolean canUseCachedMeasurement(
|
/*package*/ static boolean canUseCachedMeasurement(
|
||||||
boolean isTextNode,
|
|
||||||
float availableWidth,
|
float availableWidth,
|
||||||
float availableHeight,
|
float availableHeight,
|
||||||
float marginRow,
|
float marginRow,
|
||||||
@@ -281,38 +280,6 @@ public class LayoutEngine {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We know this to be text so we can apply some more specialized heuristics.
|
|
||||||
if (isTextNode) {
|
|
||||||
if (isWidthSame) {
|
|
||||||
if (heightMeasureMode == CSSMeasureMode.UNDEFINED) {
|
|
||||||
// Width is the same and height is not restricted. Re-use cahced value.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (heightMeasureMode == CSSMeasureMode.AT_MOST &&
|
|
||||||
cachedLayout.computedHeight < (availableHeight - marginColumn)) {
|
|
||||||
// Width is the same and height restriction is greater than the cached height. Re-use cached value.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Width is the same but height restriction imposes smaller height than previously measured.
|
|
||||||
// Update the cached value to respect the new height restriction.
|
|
||||||
cachedLayout.computedHeight = availableHeight - marginColumn;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cachedLayout.widthMeasureMode == CSSMeasureMode.UNDEFINED) {
|
|
||||||
if (widthMeasureMode == CSSMeasureMode.UNDEFINED ||
|
|
||||||
(widthMeasureMode == CSSMeasureMode.AT_MOST &&
|
|
||||||
cachedLayout.computedWidth <= (availableWidth - marginRow))) {
|
|
||||||
// Previsouly this text was measured with no width restriction, if width is now restricted
|
|
||||||
// but to a larger value than the previsouly measured width we can re-use the measurement
|
|
||||||
// as we know it will fit.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,13 +331,13 @@ public class LayoutEngine {
|
|||||||
node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]);
|
node.style.margin.getWithFallback(trailingSpacing[CSS_FLEX_DIRECTION_COLUMN], trailing[CSS_FLEX_DIRECTION_COLUMN]);
|
||||||
|
|
||||||
// First, try to use the layout cache.
|
// First, try to use the layout cache.
|
||||||
if (canUseCachedMeasurement(node.isTextNode(), availableWidth, availableHeight, marginAxisRow, marginAxisColumn,
|
if (canUseCachedMeasurement(availableWidth, availableHeight, marginAxisRow, marginAxisColumn,
|
||||||
widthMeasureMode, heightMeasureMode, layout.cachedLayout)) {
|
widthMeasureMode, heightMeasureMode, layout.cachedLayout)) {
|
||||||
cachedResults = layout.cachedLayout;
|
cachedResults = layout.cachedLayout;
|
||||||
} else {
|
} else {
|
||||||
// Try to use the measurement cache.
|
// Try to use the measurement cache.
|
||||||
for (int i = 0; i < layout.nextCachedMeasurementsIndex; i++) {
|
for (int i = 0; i < layout.nextCachedMeasurementsIndex; i++) {
|
||||||
if (canUseCachedMeasurement(node.isTextNode(), availableWidth, availableHeight, marginAxisRow, marginAxisColumn,
|
if (canUseCachedMeasurement(availableWidth, availableHeight, marginAxisRow, marginAxisColumn,
|
||||||
widthMeasureMode, heightMeasureMode, layout.cachedMeasurements[i])) {
|
widthMeasureMode, heightMeasureMode, layout.cachedMeasurements[i])) {
|
||||||
cachedResults = layout.cachedMeasurements[i];
|
cachedResults = layout.cachedMeasurements[i];
|
||||||
break;
|
break;
|
||||||
|
@@ -129,14 +129,6 @@ void jni_CSSNodeSetHasMeasureFunc(alias_ref<jobject>,
|
|||||||
CSSNodeSetMeasureFunc(_jlong2CSSNodeRef(nativePointer), hasMeasureFunc ? _jniMeasureFunc : NULL);
|
CSSNodeSetMeasureFunc(_jlong2CSSNodeRef(nativePointer), hasMeasureFunc ? _jniMeasureFunc : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_CSSNodeSetIsTextNode(alias_ref<jobject>, jlong nativePointer, jboolean isTextNode) {
|
|
||||||
CSSNodeSetIsTextnode(_jlong2CSSNodeRef(nativePointer), isTextNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
jboolean jni_CSSNodeGetIsTextNode(alias_ref<jobject>, jlong nativePointer) {
|
|
||||||
return (jboolean) CSSNodeGetIsTextnode(_jlong2CSSNodeRef(nativePointer));
|
|
||||||
}
|
|
||||||
|
|
||||||
jboolean jni_CSSNodeHasNewLayout(alias_ref<jobject>, jlong nativePointer) {
|
jboolean jni_CSSNodeHasNewLayout(alias_ref<jobject>, jlong nativePointer) {
|
||||||
return (jboolean) CSSNodeGetHasNewLayout(_jlong2CSSNodeRef(nativePointer));
|
return (jboolean) CSSNodeGetHasNewLayout(_jlong2CSSNodeRef(nativePointer));
|
||||||
}
|
}
|
||||||
@@ -209,8 +201,6 @@ jint JNI_OnLoad(JavaVM *vm, void *) {
|
|||||||
CSSMakeNativeMethod(jni_CSSNodeReset),
|
CSSMakeNativeMethod(jni_CSSNodeReset),
|
||||||
CSSMakeNativeMethod(jni_CSSNodeInsertChild),
|
CSSMakeNativeMethod(jni_CSSNodeInsertChild),
|
||||||
CSSMakeNativeMethod(jni_CSSNodeRemoveChild),
|
CSSMakeNativeMethod(jni_CSSNodeRemoveChild),
|
||||||
CSSMakeNativeMethod(jni_CSSNodeSetIsTextNode),
|
|
||||||
CSSMakeNativeMethod(jni_CSSNodeGetIsTextNode),
|
|
||||||
CSSMakeNativeMethod(jni_CSSNodeCalculateLayout),
|
CSSMakeNativeMethod(jni_CSSNodeCalculateLayout),
|
||||||
CSSMakeNativeMethod(jni_CSSNodeHasNewLayout),
|
CSSMakeNativeMethod(jni_CSSNodeHasNewLayout),
|
||||||
CSSMakeNativeMethod(jni_CSSNodeMarkDirty),
|
CSSMakeNativeMethod(jni_CSSNodeMarkDirty),
|
||||||
|
@@ -59,26 +59,6 @@ TEST(CSSLayoutTest, measure_once_single_flexible_child) {
|
|||||||
CSSNodeFreeRecursive(root);
|
CSSNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(CSSLayoutTest, remeasure_text_node_height_change) {
|
|
||||||
const CSSNodeRef root = CSSNodeNew();
|
|
||||||
CSSNodeStyleSetAlignItems(root, CSSAlignFlexStart);
|
|
||||||
|
|
||||||
const CSSNodeRef root_child0 = CSSNodeNew();
|
|
||||||
CSSNodeSetIsTextnode(root_child0, true);
|
|
||||||
CSSNodeStyleSetFlexGrow(root_child0, 1);
|
|
||||||
int measureCount = 0;
|
|
||||||
CSSNodeSetContext(root_child0, &measureCount);
|
|
||||||
CSSNodeSetMeasureFunc(root_child0, _measureMax);
|
|
||||||
CSSNodeInsertChild(root, root_child0, 0);
|
|
||||||
|
|
||||||
CSSNodeCalculateLayout(root, 100, 10, CSSDirectionLTR);
|
|
||||||
CSSNodeCalculateLayout(root, 100, 20, CSSDirectionLTR);
|
|
||||||
|
|
||||||
ASSERT_EQ(1, measureCount);
|
|
||||||
|
|
||||||
CSSNodeFreeRecursive(root);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(CSSLayoutTest, remeasure_with_same_exact_width_larger_than_needed_height) {
|
TEST(CSSLayoutTest, remeasure_with_same_exact_width_larger_than_needed_height) {
|
||||||
const CSSNodeRef root = CSSNodeNew();
|
const CSSNodeRef root = CSSNodeNew();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user