Skip to content
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

Use a separate TextPainter for intrinsics calculation in RenderEditable and RenderParagraph #144577

Conversation

LongCatIsLooong
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong commented Mar 5, 2024

Use a dedicated TextPainter for intrinsic size calculation in RenderEditable and RenderParagraph.

This is an implementation detail so the change should be covered by existing tests. Performance wise this shouldn't be significantly slower since SkParagraph caches the result of slower operations across different paragraphs. Existing benchmarks should be able to catch potential regressions (??).

The reason for making this change is to make sure that intrinsic size computations don't destroy text layout artifacts, so I can expose the text layout as a stream of immutable TextLayout objects, to signify other render objects that text-layout-dependent-cache (such as caches for getBoxesForRange which can be relatively slow to compute) should be invalidated and markNeedsPaint needs to be called if the painting logic depended on text layout.
Without this change, the intrinsics/dry layout calculations will add additional events to the text layout stream, which violates the "dry"/non-destructive contract.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Mar 5, 2024
@LongCatIsLooong LongCatIsLooong changed the title Separate text painter for intrinsics Use a separate TextPainter for intrinsics calculation in RenderEditable and RenderParagraph Mar 5, 2024
@LongCatIsLooong LongCatIsLooong force-pushed the separate-text-painter-for-intrinsics branch from 86d179b to b746a7d Compare March 5, 2024 02:29
@LongCatIsLooong
Copy link
Contributor Author

@goderbauer I'm not 100% sure this is covered by existing benchmarks. If not what kind of benchmarks do you think would be helpful? One with Text in an IntrinsicWidth/Height and keeps resizing?

void markNeedsTextLayout() {
_textLayoutLastMaxWidth = null;
_textLayoutLastMinWidth = null;
void _markNeedsTextLayout() {
Copy link
Member

Choose a reason for hiding this comment

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

Does this still need to be a separate method? Could we just call markNeedsLayout directly instead of _markNeedsTextLayout?

@@ -868,7 +875,8 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin,
return;
}
_textPainter.strutStyle = value;
markNeedsTextLayout();
_textIntrinsicsCache?.strutStyle = value;
Copy link
Member

Choose a reason for hiding this comment

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

Slightly anoying that we have to remember setting everything twice. I wonder, would it be an option to just copy the text painter configuration over when we attempt to do any intrinsics calculations?

@goderbauer
Copy link
Member

I'm not 100% sure this is covered by existing benchmarks.

As far as I know we don't really have a benchmark covering these cases.

One with Text in an IntrinsicWidth/Height and keeps resizing?

That seems like a good idea to cover this change.

auto-submit bot pushed a commit that referenced this pull request Mar 12, 2024
For #144577. There's no promise that the performance will be great when `IntrinsicHeight/IntrinsicWidth` is used extensively but it's not that uncommon of a widget.
@LongCatIsLooong LongCatIsLooong force-pushed the separate-text-painter-for-intrinsics branch from afcd70d to 2979374 Compare March 12, 2024 21:00
auto-submit bot added a commit that referenced this pull request Mar 12, 2024
…)" (#145029)

Reverts: #145007
Initiated by: LongCatIsLooong
Reason for reverting: https://ci.chromium.org/ui/p/flutter/builders/prod/Mac_android%20microbenchmarks/15561/overview
Original PR Author: LongCatIsLooong

Reviewed By: {goderbauer}

This change reverts the following previous change:
For #144577. There's no promise that the performance will be great when `IntrinsicHeight/IntrinsicWidth` is used extensively but it's not that uncommon of a widget.
@LongCatIsLooong
Copy link
Contributor Author

I ran the newly added microbenchmark locally and didn't observe a performance regression. The Google testing failures are scuba changes

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

..strutStyle = _textPainter.strutStyle
..textWidthBasis = _textPainter.textWidthBasis
..textHeightBehavior = _textPainter.textHeightBehavior;
}
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could somehow have a test to verify that the two text painters remain in sync? I don't have any ideas of how to do that, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was hoping the dry size check in RenderBox.size setter would help catch inconsistencies in the two text painters?

paragraph.paint(MockPaintingContext(), Offset.zero);
expect(getRectForA(), const Rect.fromLTWH(0, 0, 10, 10));
});

Copy link
Member

Choose a reason for hiding this comment

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

Do we have enough existing tests to cover that when you change the configuration of a RenderParagraph or RenderEditable that the new configuration is properly accounted for in the intrinsics calculations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a few tests. I couldn't think of ways to test some configurations using the test font (textDirection for example).

@goderbauer
Copy link
Member

goderbauer commented Mar 15, 2024

The Google testing failures are scuba changes

Wait, why does this change affect any goldens? Isn't that kinda unexpected?

@LongCatIsLooong
Copy link
Contributor Author

The Google testing failures are scuba changes

Wait, why does this change affect any goldens? Isn't that kinda unexpected?

TextPainter sometimes tries to lay out the text using the text's maxIntrinsic width instead of the real input width, and I think that could cause the pixel shifts in the scubas.

@LongCatIsLooong LongCatIsLooong force-pushed the separate-text-painter-for-intrinsics branch from e369503 to 3ad8461 Compare March 15, 2024 21:53
@LongCatIsLooong LongCatIsLooong added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 16, 2024
@auto-submit auto-submit bot merged commit cc01701 into flutter:master Mar 16, 2024
67 checks passed
@LongCatIsLooong LongCatIsLooong deleted the separate-text-painter-for-intrinsics branch March 16, 2024 01:16
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 16, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 16, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 17, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Mar 17, 2024
flutter/flutter@71606af...7c860dd

2024-03-17 [email protected] Roll Flutter Engine from cfbf11d757d1 to 4c420dd2dfd9 (2 revisions) (flutter/flutter#145280)
2024-03-17 [email protected] Factor out use of "print" in flutter_goldens (flutter/flutter#144846)
2024-03-16 [email protected] Roll Flutter Engine from dd4050334ff3 to cfbf11d757d1 (1 revision) (flutter/flutter#145275)
2024-03-16 [email protected] Roll Flutter Engine from 618ee6c8ba34 to dd4050334ff3 (1 revision) (flutter/flutter#145270)
2024-03-16 [email protected] Roll Flutter Engine from e4602aa149d8 to 618ee6c8ba34 (1 revision) (flutter/flutter#145266)
2024-03-16 [email protected] Roll Flutter Engine from 91b9cf24d328 to e4602aa149d8 (1 revision) (flutter/flutter#145259)
2024-03-16 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Reland #128236 "Improve build output for all platforms" (#143166)" (flutter/flutter#145261)
2024-03-16 [email protected] Reland #128236 "Improve build output for all platforms" (flutter/flutter#143166)
2024-03-16 [email protected] Introduce `Split` curve (flutter/flutter#143130)
2024-03-16 [email protected] Roll Flutter Engine from 120e52b8a1c2 to 91b9cf24d328 (1 revision) (flutter/flutter#145256)
2024-03-16 [email protected] Roll Flutter Engine from 3abc25139959 to 120e52b8a1c2 (1 revision) (flutter/flutter#145254)
2024-03-16 [email protected] Roll Flutter Engine from 6f180615e6ac to 3abc25139959 (1 revision) (flutter/flutter#145253)
2024-03-16 [email protected] Platform view devicelab ad banner scroll list real ads (flutter/flutter#145239)
2024-03-16 [email protected] Roll Flutter Engine from 6ddaa40bf1a6 to 6f180615e6ac (1 revision) (flutter/flutter#145251)
2024-03-16 [email protected] Roll Flutter Engine from d46c1fa17dda to 6ddaa40bf1a6 (1 revision) (flutter/flutter#145250)
2024-03-16 [email protected] Roll Flutter Engine from 7f15dc1200bc to d46c1fa17dda (2 revisions) (flutter/flutter#145248)
2024-03-16 [email protected] Use a separate `TextPainter` for intrinsics calculation in `RenderEditable` and `RenderParagraph` (flutter/flutter#144577)
2024-03-16 [email protected] Roll Flutter Engine from 2db915c64e6e to 7f15dc1200bc (1 revision) (flutter/flutter#145245)
2024-03-15 [email protected] Roll Flutter Engine from ba1115c30381 to 2db915c64e6e (2 revisions) (flutter/flutter#145240)
2024-03-15 [email protected] Roll Flutter Engine from c2fd5333a5d2 to ba1115c30381 (3 revisions) (flutter/flutter#145237)
2024-03-15 [email protected] Renaming the virtual device Nexus5 name to Nexus5.gce_x86 (flutter/flutter#145225)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@TahaTesser TahaTesser mentioned this pull request Mar 20, 2024
9 tasks
@TahaTesser
Copy link
Member

@LongCatIsLooong
My PR #143932 fails web HTML renderer tests after this PR and potentially also failing #142804 tests.

@LongCatIsLooong
Copy link
Contributor Author

@LongCatIsLooong My PR #143932 fails web HTML renderer tests after this PR and potentially also failing #142804 tests.

I'll take a look in a bit.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 14, 2024
zmtzawqlp added a commit to fluttercandies/extended_text that referenced this pull request May 31, 2024
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
flutter/flutter@71606af...7c860dd

2024-03-17 [email protected] Roll Flutter Engine from cfbf11d757d1 to 4c420dd2dfd9 (2 revisions) (flutter/flutter#145280)
2024-03-17 [email protected] Factor out use of "print" in flutter_goldens (flutter/flutter#144846)
2024-03-16 [email protected] Roll Flutter Engine from dd4050334ff3 to cfbf11d757d1 (1 revision) (flutter/flutter#145275)
2024-03-16 [email protected] Roll Flutter Engine from 618ee6c8ba34 to dd4050334ff3 (1 revision) (flutter/flutter#145270)
2024-03-16 [email protected] Roll Flutter Engine from e4602aa149d8 to 618ee6c8ba34 (1 revision) (flutter/flutter#145266)
2024-03-16 [email protected] Roll Flutter Engine from 91b9cf24d328 to e4602aa149d8 (1 revision) (flutter/flutter#145259)
2024-03-16 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Reland #128236 "Improve build output for all platforms" (#143166)" (flutter/flutter#145261)
2024-03-16 [email protected] Reland #128236 "Improve build output for all platforms" (flutter/flutter#143166)
2024-03-16 [email protected] Introduce `Split` curve (flutter/flutter#143130)
2024-03-16 [email protected] Roll Flutter Engine from 120e52b8a1c2 to 91b9cf24d328 (1 revision) (flutter/flutter#145256)
2024-03-16 [email protected] Roll Flutter Engine from 3abc25139959 to 120e52b8a1c2 (1 revision) (flutter/flutter#145254)
2024-03-16 [email protected] Roll Flutter Engine from 6f180615e6ac to 3abc25139959 (1 revision) (flutter/flutter#145253)
2024-03-16 [email protected] Platform view devicelab ad banner scroll list real ads (flutter/flutter#145239)
2024-03-16 [email protected] Roll Flutter Engine from 6ddaa40bf1a6 to 6f180615e6ac (1 revision) (flutter/flutter#145251)
2024-03-16 [email protected] Roll Flutter Engine from d46c1fa17dda to 6ddaa40bf1a6 (1 revision) (flutter/flutter#145250)
2024-03-16 [email protected] Roll Flutter Engine from 7f15dc1200bc to d46c1fa17dda (2 revisions) (flutter/flutter#145248)
2024-03-16 [email protected] Use a separate `TextPainter` for intrinsics calculation in `RenderEditable` and `RenderParagraph` (flutter/flutter#144577)
2024-03-16 [email protected] Roll Flutter Engine from 2db915c64e6e to 7f15dc1200bc (1 revision) (flutter/flutter#145245)
2024-03-15 [email protected] Roll Flutter Engine from ba1115c30381 to 2db915c64e6e (2 revisions) (flutter/flutter#145240)
2024-03-15 [email protected] Roll Flutter Engine from c2fd5333a5d2 to ba1115c30381 (3 revisions) (flutter/flutter#145237)
2024-03-15 [email protected] Renaming the virtual device Nexus5 name to Nexus5.gce_x86 (flutter/flutter#145225)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
zmtzawqlp added a commit to fluttercandies/extended_text that referenced this pull request Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants