perf: optimize render layout invalidation#85
Open
KoalaHao wants to merge 3 commits into
Open
Conversation
The optimization commit 2450c6d ('Optimize render layout invalidation') introduced relayout boundaries that skip cascading markNeedsLayout up to the parent when the parent doesn't use the child's size. RenderLayoutBuilder was passing 'parentUsesSize: !constraints.isTight' to its child, which evaluated to false under tight constraints and broke the propagation chain. When the chat toolbar's LayoutBuilder's container child marked itself dirty (e.g. from inner streaming widgets), the dirty mark never reached LayoutBuilder or its parent, so the toolbar's _layoutCallback never re-ran and children rendered with stale state. Fix: always pass 'parentUsesSize: true' because RenderLayoutBuilder ALWAYS derives its size from its child (size = constraints.constrain(child.size) at the bottom of performLayout). The previous code was a lie that the optimization was happily exploiting. Adds 17 tests in layout_invalidation_optimization_test.dart covering: - Relayout boundaries (parentUsesSize=false/true propagation) - RenderText.text setter optimization (same-footprint skip, size-changing relayout, _layoutResult updates, style-only) - markNeedsLayout propagation semantics - RenderLayoutBuilder child chain (incl. direct regression test that catches the bug — fails under old code, passes after fix) - Streaming widget repaint path (style-only, same-width, size-changing, multi-update cascade) All 1428 nocterm tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RenderLayoutBuilderchild dirty marks always cascade when its child can affect layout.Tests
dart analyzedart test test/framework/layout_invalidation_optimization_test.dart test/framework/relayout_boundary_test.dart test/framework/render_object_invalidation_optimization_test.dart test/framework/render_pipeline_test.dart