From 5d2f0c0f4fa2769f9cd7cd41ad40f7a99c13d541 Mon Sep 17 00:00:00 2001 From: GitHub Workflows Support Date: Mon, 23 Nov 2026 06:06:19 -0800 Subject: [PATCH] Compute isBaselineLayout once per container instead of once per flex line (#2090) Summary: isBaselineLayout walks every layout child of the container. justifyMainAxis called it once per flex line, so a wrapping container with N children and L lines did O(N * L) work. Compute it once before the line loop and reuse it in justifyMainAxis and in multi-line content alignment. Reviewed By: javache Differential Revision: D131401933 --- .../yoga/yoga/algorithm/CalculateLayout.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index 4822e13955e..3d7e570e520 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -1725,7 +1725,8 @@ static void justifyMainAxis( const float availableInnerMainDim, const float availableInnerCrossDim, const float availableInnerWidth, - const bool performLayout) { + const bool performLayout, + const bool isNodeBaselineLayout) { const auto& style = node->style(); const float leadingPaddingAndBorderMain = @@ -1821,7 +1822,6 @@ static void justifyMainAxis( float maxAscentForCurrentLine = 0; float maxDescentForCurrentLine = 0; - bool isNodeBaselineLayout = isBaselineLayout(node); for (auto child : flexLine.itemsInFlow) { const LayoutResults& childLayout = child->getLayout(); if (child->style().flexStartMarginIsAuto(mainAxis, direction) && @@ -2223,6 +2223,7 @@ static void calculateLayoutImpl( // Max main dimension of all the lines. float maxLineMainDim = 0; + const bool isNodeBaselineLayout = isBaselineLayout(node); for (; startOfLineIterator != node->getLayoutChildren().end(); lineCount++) { auto flexLine = calculateFlexLine( node, @@ -2361,7 +2362,8 @@ static void calculateLayoutImpl( availableInnerMainDim, availableInnerCrossDim, availableInnerWidth, - performLayout); + performLayout, + isNodeBaselineLayout); float containerCrossAxis = availableInnerCrossDim; if (sizingModeCrossDim == SizingMode::MaxContent || @@ -2523,7 +2525,7 @@ static void calculateLayoutImpl( // STEP 8: MULTI-LINE CONTENT ALIGNMENT // currentLead stores the size of the cross dim - if (performLayout && (isNodeFlexWrap || isBaselineLayout(node))) { + if (performLayout && (isNodeFlexWrap || isNodeBaselineLayout)) { float leadPerLine = 0; float currentLead = leadingPaddingAndBorderCross; float extraSpacePerLine = 0;