Skip to content

Measure with exact measurement when stretch is defined#193

Merged
emilsjolander merged 1 commit into
react:masterfrom
emilsjolander:stretch-perf
Jun 9, 2016
Merged

Measure with exact measurement when stretch is defined#193
emilsjolander merged 1 commit into
react:masterfrom
emilsjolander:stretch-perf

Conversation

@emilsjolander

Copy link
Copy Markdown
Contributor

An optimization which will measure with EXACTLY when possible given stretch alignment. Text measurement specifically is much more performant when it knows the exact measurement up front and given that stretch alignment is the default this has quite a big performance impact on certain types of layouts.

@emilsjolander

Copy link
Copy Markdown
Contributor Author

I'm assuming my environment is set up differently than the person who last generated the code. That is why so many lines are whitespace removal.

@emilsjolander

Copy link
Copy Markdown
Contributor Author

@rigdern Would love it if you took a look

Comment thread dist/css-layout.h Outdated

// If child has no defined size in the cross axis and is set to stretch, set the cross
// axis to be measured exactly with the available inner width
if (!isMainAxisRow && !isUndefined(availableInnerWidth) && !isStyleDimDefined(child, CSS_FLEX_DIRECTION_ROW) && widthMeasureMode == CSS_MEASURE_MODE_EXACTLY && getAlignItem(node, child) == CSS_ALIGN_STRETCH) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment to indicate that these branches are for an optimization rather than a functional requirement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not just for perf though. It is also more correct to measure children with EXACTLY as that is what and alignment of stretch enforces.

@rigdern

rigdern commented Jun 2, 2016

Copy link
Copy Markdown

@emilsjolander Where does the performance win come from? Do you have an example layout?

In case you weren't aware, you can view the changes while ignoring whitespace by adding ?w=1 to the end of the URL. For example: https://github.com/facebook/css-layout/pull/193/files?w=1. However, I don't think you can write or view comments in this view :(

@emilsjolander

Copy link
Copy Markdown
Contributor Author

I tried to describe it in the PR description but I'll expand on it a bit.

In a simple layout such as

<View style={{width: 1000}}>
  <Text>zZzZ</Text>
  <Text>zZzZzZzZ</Text>
  <Text>zZzZzZzZzZzZ</Text>
</View>

View defaults to alignItems: 'stretch' which previous to this diff would initially measure children with AT_MOST width. Not only is this wrong as they should be measured with an exact width due to there alignment it is also bad for performance as the text itself needs to figure out how big it is instead of being told a size.

Comment thread src/Layout.js Outdated

// If child has no defined size in the cross axis and is set to stretch, set the cross
// axis to be measured exactly with the available inner width
if (!isMainAxisRow && !isUndefined(availableInnerWidth) && !isStyleDimDefined(child, CSS_FLEX_DIRECTION_ROW) && widthMeasureMode == CSS_MEASURE_MODE_EXACTLY && getAlignItem(node, child) == CSS_ALIGN_STRETCH) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break this down into multiple lines?

@rigdern

rigdern commented Jun 8, 2016

Copy link
Copy Markdown

@emilsjolander Sorry for the delay. I tested this change today in our app and didn't notice any issues.

Your change looks good to me.

@emilsjolander

Copy link
Copy Markdown
Contributor Author

Thanks Adam!
On Tue, 7 Jun 2016 at 23:35, Adam Comella notifications@github.com wrote:

@emilsjolander https://github.com/emilsjolander Sorry for the delay. I
tested this change today in our app and didn't notice any issues.

Your change looks good to me.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#193 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ABdIpG-GDc3bUTJjTvxucFyBt20h45xjks5qJjiHgaJpZM4IsuJM
.

Comment thread dist/css-layout.h
childWidth = updatedMainSize + getMarginAxis(currentRelativeChild, CSS_FLEX_DIRECTION_ROW);
childWidthMeasureMode = CSS_MEASURE_MODE_EXACTLY;

if (!isStyleDimDefined(currentRelativeChild, CSS_FLEX_DIRECTION_COLUMN)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap in multiple lines

@lucasr

lucasr commented Jun 8, 2016

Copy link
Copy Markdown
Contributor

Looks good with nits fixed.

@emilsjolander emilsjolander merged commit 45e595e into react:master Jun 9, 2016
ghost pushed a commit to react/react-native that referenced this pull request Jun 13, 2016
Summary:
Import latest master from css-layout.

This includes the following pull requests:
react/yoga#192
react/yoga#193
react/yoga#195
react/yoga#196

Reviewed By: javache

Differential Revision: D3411535

fbshipit-source-id: 95bee9bd0282f98f6fafa15335b910b644395ad3
jordwalke added a commit to jordwalke/css-layout that referenced this pull request Oct 7, 2016
…en stretch is defined)

react#193
react@2a816bf

This doesn't make any more tests pass or fail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants