Make CompactValue internal detail of yoga::Style
(#1492)
Summary: X-link: https://github.com/facebook/react-native/pull/41776 Pull Request resolved: https://github.com/facebook/yoga/pull/1492 # Summary In preparation to replace `CompactValue`, this fully encapsulates it as an implementation detail of `yoga::Style`. The internal API now always operates on `Style::Length`, converted to `YGValue` at the public API boundary. In the next step, we can plug in a new representation within `Style`, which should enable 64 bit values, and lower memory usage. # Test Plan 1. Existing tests (inc for style, invalidation, CompactValue) pass 2. Check that constexpr `yoga::isinf()` produces same assembly under Clang as `std::isinf()` 3. Fabric Android builds 4. Yoga benchmark does style reads # Performance Checking whether a style is defined, then reading after, is a hot path, and we are doubling any space style lengths take in the stack (but not long-term on the node). After a naive move, on one system, the Yoga benchmark creating, laying out, and destroying a tree, ran about 8-10% slower in the "Huge nested flex" example. We are converting in many more cases instead of doing undefined check, but operating on accessed style values no longer needs to do the conversion multiple times. I changed the `CompactValue` conversion to YGValue/StyleLength path to check for undefined as the common case (since we always convert, instead of calling `isUndefined` directly on CompactValue. That seemed to get the difference down to ~5-6% when I was playing with it then. We can optimistically make some of this up with ValuePool giving better locality, and fix this more holistically if we reduce edge and value resolution. On another machine where I tested this, the new revision went the opposite direction, and was about 5% faster, so this isn't really a cut and dry regression, but we see different characteristics than before. # Changelog [Internal] Reviewed By: rozele Differential Revision: D51775346 fbshipit-source-id: c618af41b4882b4a227c917fcad07375806faf78
This commit is contained in:
committed by
Facebook GitHub Bot
parent
2caa8ac8cb
commit
192016a0a8
@@ -127,8 +127,8 @@ bool Node::isFlexStartPositionDefined(FlexDirection axis, Direction direction)
|
||||
|
||||
bool Node::isInlineStartPositionDefined(FlexDirection axis, Direction direction)
|
||||
const {
|
||||
const Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||
auto leadingPosition = isRow(axis)
|
||||
Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||
Style::Length leadingPosition = isRow(axis)
|
||||
? computeEdgeValueForRow<&Style::position>(Edge::Start, startEdge)
|
||||
: computeEdgeValueForColumn<&Style::position>(startEdge);
|
||||
|
||||
@@ -148,8 +148,8 @@ bool Node::isFlexEndPositionDefined(FlexDirection axis, Direction direction)
|
||||
|
||||
bool Node::isInlineEndPositionDefined(FlexDirection axis, Direction direction)
|
||||
const {
|
||||
const Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||
auto trailingPosition = isRow(axis)
|
||||
Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||
Style::Length trailingPosition = isRow(axis)
|
||||
? computeEdgeValueForRow<&Style::position>(Edge::End, endEdge)
|
||||
: computeEdgeValueForColumn<&Style::position>(endEdge);
|
||||
|
||||
@@ -173,8 +173,8 @@ float Node::getInlineStartPosition(
|
||||
FlexDirection axis,
|
||||
Direction direction,
|
||||
float axisSize) const {
|
||||
const Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||
auto leadingPosition = isRow(axis)
|
||||
Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||
Style::Length leadingPosition = isRow(axis)
|
||||
? computeEdgeValueForRow<&Style::position>(Edge::Start, startEdge)
|
||||
: computeEdgeValueForColumn<&Style::position>(startEdge);
|
||||
|
||||
@@ -198,8 +198,8 @@ float Node::getInlineEndPosition(
|
||||
FlexDirection axis,
|
||||
Direction direction,
|
||||
float axisSize) const {
|
||||
const Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||
auto trailingPosition = isRow(axis)
|
||||
Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||
Style::Length trailingPosition = isRow(axis)
|
||||
? computeEdgeValueForRow<&Style::position>(Edge::End, endEdge)
|
||||
: computeEdgeValueForColumn<&Style::position>(endEdge);
|
||||
|
||||
@@ -223,8 +223,8 @@ float Node::getInlineStartMargin(
|
||||
FlexDirection axis,
|
||||
Direction direction,
|
||||
float widthSize) const {
|
||||
const Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||
auto leadingMargin = isRow(axis)
|
||||
Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||
Style::Length leadingMargin = isRow(axis)
|
||||
? computeEdgeValueForRow<&Style::margin>(Edge::Start, startEdge)
|
||||
: computeEdgeValueForColumn<&Style::margin>(startEdge);
|
||||
|
||||
@@ -248,8 +248,8 @@ float Node::getInlineEndMargin(
|
||||
FlexDirection axis,
|
||||
Direction direction,
|
||||
float widthSize) const {
|
||||
const Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||
auto trailingMargin = isRow(axis)
|
||||
Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||
Style::Length trailingMargin = isRow(axis)
|
||||
? computeEdgeValueForRow<&Style::margin>(Edge::End, endEdge)
|
||||
: computeEdgeValueForColumn<&Style::margin>(endEdge);
|
||||
|
||||
@@ -258,49 +258,49 @@ float Node::getInlineEndMargin(
|
||||
|
||||
float Node::getInlineStartBorder(FlexDirection axis, Direction direction)
|
||||
const {
|
||||
const Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||
YGValue leadingBorder = isRow(axis)
|
||||
Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||
Style::Length leadingBorder = isRow(axis)
|
||||
? computeEdgeValueForRow<&Style::border>(Edge::Start, startEdge)
|
||||
: computeEdgeValueForColumn<&Style::border>(startEdge);
|
||||
|
||||
return maxOrDefined(leadingBorder.value, 0.0f);
|
||||
return maxOrDefined(leadingBorder.value().unwrap(), 0.0f);
|
||||
}
|
||||
|
||||
float Node::getFlexStartBorder(FlexDirection axis, Direction direction) const {
|
||||
YGValue leadingBorder = isRow(axis)
|
||||
Style::Length leadingBorder = isRow(axis)
|
||||
? computeEdgeValueForRow<&Style::border>(
|
||||
getFlexStartRelativeEdgeUsingErrata(axis, direction),
|
||||
flexStartEdge(axis))
|
||||
: computeEdgeValueForColumn<&Style::border>(flexStartEdge(axis));
|
||||
|
||||
return maxOrDefined(leadingBorder.value, 0.0f);
|
||||
return maxOrDefined(leadingBorder.value().unwrap(), 0.0f);
|
||||
}
|
||||
|
||||
float Node::getInlineEndBorder(FlexDirection axis, Direction direction) const {
|
||||
const Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||
YGValue trailingBorder = isRow(axis)
|
||||
Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||
Style::Length trailingBorder = isRow(axis)
|
||||
? computeEdgeValueForRow<&Style::border>(Edge::End, endEdge)
|
||||
: computeEdgeValueForColumn<&Style::border>(endEdge);
|
||||
|
||||
return maxOrDefined(trailingBorder.value, 0.0f);
|
||||
return maxOrDefined(trailingBorder.value().unwrap(), 0.0f);
|
||||
}
|
||||
|
||||
float Node::getFlexEndBorder(FlexDirection axis, Direction direction) const {
|
||||
YGValue trailingBorder = isRow(axis)
|
||||
Style::Length trailingBorder = isRow(axis)
|
||||
? computeEdgeValueForRow<&Style::border>(
|
||||
getFlexEndRelativeEdgeUsingErrata(axis, direction),
|
||||
flexEndEdge(axis))
|
||||
: computeEdgeValueForColumn<&Style::border>(flexEndEdge(axis));
|
||||
|
||||
return maxOrDefined(trailingBorder.value, 0.0f);
|
||||
return maxOrDefined(trailingBorder.value().unwrap(), 0.0f);
|
||||
}
|
||||
|
||||
float Node::getInlineStartPadding(
|
||||
FlexDirection axis,
|
||||
Direction direction,
|
||||
float widthSize) const {
|
||||
const Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||
auto leadingPadding = isRow(axis)
|
||||
Edge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||
Style::Length leadingPadding = isRow(axis)
|
||||
? computeEdgeValueForRow<&Style::padding>(Edge::Start, startEdge)
|
||||
: computeEdgeValueForColumn<&Style::padding>(startEdge);
|
||||
|
||||
@@ -324,8 +324,8 @@ float Node::getInlineEndPadding(
|
||||
FlexDirection axis,
|
||||
Direction direction,
|
||||
float widthSize) const {
|
||||
const Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||
auto trailingPadding = isRow(axis)
|
||||
Edge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||
Style::Length trailingPadding = isRow(axis)
|
||||
? computeEdgeValueForRow<&Style::padding>(Edge::End, endEdge)
|
||||
: computeEdgeValueForColumn<&Style::padding>(endEdge);
|
||||
|
||||
@@ -424,16 +424,18 @@ bool Node::isLayoutDimensionDefined(const FlexDirection axis) {
|
||||
bool Node::styleDefinesDimension(
|
||||
const FlexDirection axis,
|
||||
const float ownerSize) {
|
||||
bool isDefined = yoga::isDefined(getResolvedDimension(dimension(axis)).value);
|
||||
|
||||
auto resolvedDimension = getResolvedDimension(dimension(axis));
|
||||
if (!resolvedDimension.isDefined()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !(
|
||||
resolvedDimension.unit == YGUnitAuto ||
|
||||
resolvedDimension.unit == YGUnitUndefined ||
|
||||
(resolvedDimension.unit == YGUnitPoint && isDefined &&
|
||||
resolvedDimension.value < 0.0f) ||
|
||||
(resolvedDimension.unit == YGUnitPercent && isDefined &&
|
||||
(resolvedDimension.value < 0.0f || yoga::isUndefined(ownerSize))));
|
||||
resolvedDimension.isAuto() ||
|
||||
(resolvedDimension.unit() == Unit::Point &&
|
||||
resolvedDimension.value().unwrap() < 0.0f) ||
|
||||
(resolvedDimension.unit() == Unit::Percent &&
|
||||
(resolvedDimension.value().unwrap() < 0.0f ||
|
||||
yoga::isUndefined(ownerSize))));
|
||||
}
|
||||
|
||||
// Setters
|
||||
@@ -621,7 +623,7 @@ void Node::setPosition(
|
||||
crossAxisTrailingEdge);
|
||||
}
|
||||
|
||||
YGValue Node::getFlexStartMarginValue(FlexDirection axis) const {
|
||||
Style::Length Node::getFlexStartMarginValue(FlexDirection axis) const {
|
||||
if (isRow(axis) && style_.margin(Edge::Start).isDefined()) {
|
||||
return style_.margin(Edge::Start);
|
||||
} else {
|
||||
@@ -629,7 +631,7 @@ YGValue Node::getFlexStartMarginValue(FlexDirection axis) const {
|
||||
}
|
||||
}
|
||||
|
||||
YGValue Node::marginTrailingValue(FlexDirection axis) const {
|
||||
Style::Length Node::marginTrailingValue(FlexDirection axis) const {
|
||||
if (isRow(axis) && style_.margin(Edge::End).isDefined()) {
|
||||
return style_.margin(Edge::End);
|
||||
} else {
|
||||
@@ -637,15 +639,15 @@ YGValue Node::marginTrailingValue(FlexDirection axis) const {
|
||||
}
|
||||
}
|
||||
|
||||
YGValue Node::resolveFlexBasisPtr() const {
|
||||
YGValue flexBasis = style_.flexBasis();
|
||||
if (flexBasis.unit != YGUnitAuto && flexBasis.unit != YGUnitUndefined) {
|
||||
Style::Length Node::resolveFlexBasisPtr() const {
|
||||
Style::Length flexBasis = style_.flexBasis();
|
||||
if (flexBasis.unit() != Unit::Auto && flexBasis.unit() != Unit::Undefined) {
|
||||
return flexBasis;
|
||||
}
|
||||
if (style_.flex().isDefined() && style_.flex().unwrap() > 0.0f) {
|
||||
return config_->useWebDefaults() ? YGValueAuto : YGValueZero;
|
||||
return config_->useWebDefaults() ? value::ofAuto() : value::points(0);
|
||||
}
|
||||
return YGValueAuto;
|
||||
return value::ofAuto();
|
||||
}
|
||||
|
||||
void Node::resolveDimension() {
|
||||
|
Reference in New Issue
Block a user