Skip to content

Clear the baseline cache when RenderBox is laid out #101493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feedback
  • Loading branch information
xu-baolin committed Apr 27, 2022
commit dc355bcc702fd7773306334436203d9384ae99eb
4 changes: 1 addition & 3 deletions packages/flutter/lib/src/rendering/box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,6 @@ abstract class RenderBox extends RenderObject {
bool _computingThisDryLayout = false;

bool _notifyParentIfDirty = false;
Constraints? _lastConstraints;

/// Returns the [Size] that this [RenderBox] would like to be given the
/// provided [BoxConstraints].
Expand Down Expand Up @@ -2380,9 +2379,8 @@ abstract class RenderBox extends RenderObject {

@override
void layout(Constraints constraints, {bool parentUsesSize = false}) {
if (constraints != _lastConstraints) {
if (hasSize && constraints != this.constraints) {
_clearCachedData();
Copy link
Member

Choose a reason for hiding this comment

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

I think we only need to invalidate the baseline cache here? The intrinsics calculations are per definition independent of constraints.

Copy link
Member Author

@xu-baolin xu-baolin Apr 27, 2022

Choose a reason for hiding this comment

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

1, We clear all the caches when the RO was marked dirty, so clear them when lay-out is reasonable.
2, Folks also can custom a RO that let the intrinsics dependent on constraints like the related issue.
3, The _cachedDryLayoutSizes were strongly dependent on constraints, I don't want to treat them differently.

Copy link
Member

Choose a reason for hiding this comment

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

  1. Clearing the cache unnecessarily will make it less useful.
  2. Per definition, intrinsics are independent of constraints. If an RO uses constraints to calculate intrinsics, that's a bug. It will also be hard to write such an implementation since the intrinsics methods are usually called before layout...
  3. _cachedDryLayoutSizes is dependent on the constraints that were passed to computeDryLayout (not the constraints passed to layout here). Furthermore, the dry layout size cache is keyed on constraints - and for the same constraints it should always calculate the same intrinsics size (all things being equal). So, clearing the cache when constraints change is not necessary.

Choose a reason for hiding this comment

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

Expose relevant calculation methods, shield debug detection, and allow the demander to bypass the cache directly when needed. This is the easiest way to fix. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. Clearing the cache unnecessarily will make it less useful.

  2. Per definition, intrinsics are independent of constraints. If an RO uses constraints to calculate intrinsics, that's a bug. It will also be hard to write such an implementation since the intrinsics methods are usually called before layout...

  3. _cachedDryLayoutSizes is dependent on the constraints that were passed to computeDryLayout (not the constraints passed to layout here). Furthermore, the dry layout size cache is keyed on constraints - and for the same constraints it should always calculate the same intrinsics size (all things being equal). So, clearing the cache when constraints change is not necessary.

Yes I understand now. Thanks for explaining this.

_lastConstraints = constraints;
}
super.layout(constraints, parentUsesSize: parentUsesSize);
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy