Bug 230755 - [css-flexbox] Improve & simplify the flex-basis computation
Summary: [css-flexbox] Improve & simplify the flex-basis computation
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sergio Villar Senin
URL:
Keywords: InRadar
Depends on: 232481
Blocks:
  Show dependency treegraph
 
Reported: 2021-09-24 09:36 PDT by Sergio Villar Senin
Modified: 2022-05-04 08:59 PDT (History)
19 users (show)

See Also:


Attachments
Patch (17.06 KB, patch)
2021-09-24 10:09 PDT, Sergio Villar Senin
no flags Details | Formatted Diff | Diff
Patch for landing (17.23 KB, patch)
2021-10-15 01:39 PDT, Sergio Villar Senin
no flags Details | Formatted Diff | Diff
Patch (25.61 KB, patch)
2021-11-10 02:35 PST, Sergio Villar Senin
zalan: review+
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sergio Villar Senin 2021-09-24 09:36:50 PDT
[css-flexbox] Improve & simplify the flex-basis computation
Comment 1 Sergio Villar Senin 2021-09-24 10:09:42 PDT
Created attachment 439157 [details]
Patch
Comment 2 Sergio Villar Senin 2021-10-01 04:39:56 PDT
Gentle ping for reviewers
Comment 3 Radar WebKit Bug Importer 2021-10-01 09:39:59 PDT
<rdar://problem/83769781>
Comment 4 Rob Buis 2021-10-05 00:20:31 PDT
Comment on attachment 439157 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=439157&action=review

> Source/WebCore/rendering/RenderFlexibleBox.cpp:1016
> +            m_child.mutableStyle().setLogicalWidth(Length(m_originalMainAxisLength));

Temp Length not needed.

> Source/WebCore/rendering/RenderFlexibleBox.cpp:1018
> +            m_child.mutableStyle().setLogicalHeight(Length(m_originalMainAxisLength));

Ditto.
Comment 5 Sergio Villar Senin 2021-10-06 09:39:37 PDT
Any other comment regarding this patch?
Comment 6 Sergio Villar Senin 2021-10-08 07:48:00 PDT
(In reply to Rob Buis from comment #4)
> Comment on attachment 439157 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=439157&action=review
> 
> > Source/WebCore/rendering/RenderFlexibleBox.cpp:1016
> > +            m_child.mutableStyle().setLogicalWidth(Length(m_originalMainAxisLength));
> 
> Temp Length not needed.

You actually need that or a WTFMove
Comment 7 Rob Buis 2021-10-08 08:04:35 PDT
Comment on attachment 439157 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=439157&action=review

>>> Source/WebCore/rendering/RenderFlexibleBox.cpp:1016
>>> +            m_child.mutableStyle().setLogicalWidth(Length(m_originalMainAxisLength));
>> 
>> Temp Length not needed.
> 
> You actually need that or a WTFMove

Ah I see! WTFMove would be more efficient here, right?
Comment 8 Manuel Rego Casasnovas 2021-10-13 04:34:56 PDT
Comment on attachment 439157 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=439157&action=review

Nice patch, I have some comments and questions inline.

> Source/WebCore/rendering/RenderFlexibleBox.cpp:999
> +class ScopedFlexBasisAsMainSize {

Wow, this is quite a hack I guess we don't have a better alternative though. :-(

I'm not really sure about the class name, would be better ScopedFlexBasisAsChildSize? Or something else, not sure...

> Source/WebCore/rendering/RenderFlexibleBox.cpp:1007
> +            m_child.mutableStyle().setLogicalWidth(Length(flexBasis));

Does this works fine if the element has something like "max-width: 100px;" or "min-width: 1000px;".
Not sure if preferred widths are recomputed or not after this call.

> Source/WebCore/rendering/RenderFlexibleBox.cpp:1023
> +    Length m_originalMainAxisLength;

Why not just "m_originalSize" or "m_originalChildSize"?

> Source/WebCore/rendering/RenderFlexibleBox.cpp:1040
> +    // 9.3.2 E. Otherwise, size the item into the available space using its used flex basis in place of its main size.

I miss C) and D) before getting to E). Maybe we could add a comment.

> Source/WebCore/rendering/RenderFlexibleBox.cpp:1047
> +        if (childHasIntrinsicMainAxisSize(child))
> +            child.setNeedsLayout(MarkOnlyThis);

Why we need this?

> Source/WebCore/rendering/RenderFlexibleBox.cpp:1048
> +        child.layoutIfNeeded();

Ditto about this like, do we need this if we haven't gone through the previous if statement?
Comment 9 Sergio Villar Senin 2021-10-13 05:11:07 PDT
Comment on attachment 439157 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=439157&action=review

>> Source/WebCore/rendering/RenderFlexibleBox.cpp:1007
>> +            m_child.mutableStyle().setLogicalWidth(Length(flexBasis));
> 
> Does this works fine if the element has something like "max-width: 100px;" or "min-width: 1000px;".
> Not sure if preferred widths are recomputed or not after this call.

This is a nice question. When computing the flex-base size the min|max constrains should not apply. We are not doing that at the moment, however that is properly addressed in https://bugs.webkit.org/show_bug.cgi?id=225590. That bug landed and caused some regression, I have a local patch that implements https://bugs.webkit.org/show_bug.cgi?id=225590 on top of this patch and that does not regress anything.

>> Source/WebCore/rendering/RenderFlexibleBox.cpp:1023
>> +    Length m_originalMainAxisLength;
> 
> Why not just "m_originalSize" or "m_originalChildSize"?

OK, I don't have a strong opinion here.

>> Source/WebCore/rendering/RenderFlexibleBox.cpp:1040
>> +    // 9.3.2 E. Otherwise, size the item into the available space using its used flex basis in place of its main size.
> 
> I miss C) and D) before getting to E). Maybe we could add a comment.

They've not been implemented yet.

>> Source/WebCore/rendering/RenderFlexibleBox.cpp:1047
>> +            child.setNeedsLayout(MarkOnlyThis);
> 
> Why we need this?

We were already doing this in the code that was removed from constructFlexItem(). At this point we know that we need to return the logical height of the item so we must ensure that we have an updated value for the height before. The only way to do that is laying out the item

>> Source/WebCore/rendering/RenderFlexibleBox.cpp:1048
>> +        child.layoutIfNeeded();
> 
> Ditto about this like, do we need this if we haven't gone through the previous if statement?

Yep, because you don't have the height until you layout the item.
Comment 10 Manuel Rego Casasnovas 2021-10-14 04:48:41 PDT
Comment on attachment 439157 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=439157&action=review

r=me

>> Source/WebCore/rendering/RenderFlexibleBox.cpp:999
>> +class ScopedFlexBasisAsMainSize {
> 
> Wow, this is quite a hack I guess we don't have a better alternative though. :-(
> 
> I'm not really sure about the class name, would be better ScopedFlexBasisAsChildSize? Or something else, not sure...

Could we add some brief documentation about this class? Is it not very big, but it's a kind of very special case, so it's worth explaining it for the future.

>>> Source/WebCore/rendering/RenderFlexibleBox.cpp:1040
>>> +    // 9.3.2 E. Otherwise, size the item into the available space using its used flex basis in place of its main size.
>> 
>> I miss C) and D) before getting to E). Maybe we could add a comment.
> 
> They've not been implemented yet.

I'd add a comment for clarity, otherwise it's kind of confusing.
Comment 11 zalan 2021-10-14 19:49:23 PDT
👍
Comment 12 Sergio Villar Senin 2021-10-15 01:39:59 PDT
Created attachment 441350 [details]
Patch for landing
Comment 13 Sergio Villar Senin 2021-10-18 03:08:03 PDT
Committed r284359 (243144@main): <https://commits.webkit.org/243144@main>
Comment 14 Yusuke Suzuki 2021-10-29 13:18:59 PDT
Reverted in https://trac.webkit.org/changeset/285045/webkit
This patch makes Twitter CPU usage 100%.
Comment 15 Antti Koivisto 2021-11-03 02:54:32 PDT
Comment on attachment 441350 [details]
Patch for landing

View in context: https://bugs.webkit.org/attachment.cgi?id=441350&action=review

> Source/WebCore/rendering/RenderFlexibleBox.cpp:1012
> +        m_child.mutableStyle().setLogicalHeight(Length(flexBasis));

This sort of hacks are not ok.
Comment 16 Sergio Villar Senin 2021-11-10 02:35:38 PST
Created attachment 443788 [details]
Patch
Comment 17 Sergio Villar Senin 2021-11-11 01:42:26 PST
Committed r285623 (244124@main): <https://commits.webkit.org/244124@main>
Comment 18 zalan 2022-05-04 08:59:57 PDT
This broke the IRS payment page. see bug 240068.