Skip to content

Conversation

@GaryQian
Copy link
Contributor

@GaryQian GaryQian commented Dec 10, 2019

Description

Passing Rect.zero would cache the zero caretProto, which would cause future calls to perform redundant computation.

Pass the proper _caretPrototype to ensure the cached version is not discarded.

Related Issues

Fixes #24522

Tests

Added perf test.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.

Before:
"average_frame_build_time_millis": 3.5870540540540534,
"90th_percentile_frame_build_time_millis": 6.709,
"99th_percentile_frame_build_time_millis": 24.555,
"worst_frame_build_time_millis": 24.555,
"missed_frame_build_budget_count": 1,
"average_frame_rasterizer_time_millis": 6.6930000000000005,
"90th_percentile_frame_rasterizer_time_millis": 6.919,
"99th_percentile_frame_rasterizer_time_millis": 70.695,
"worst_frame_rasterizer_time_millis": 70.695,
"missed_frame_rasterizer_budget_count": 2,
"frame_count": 37,

After:
"average_frame_build_time_millis": 3.3834864864864858,
"90th_percentile_frame_build_time_millis": 4.756,
"99th_percentile_frame_build_time_millis": 24.9,
"worst_frame_build_time_millis": 24.9,
"missed_frame_build_budget_count": 1,
"average_frame_rasterizer_time_millis": 6.965729729729728,
"90th_percentile_frame_rasterizer_time_millis": 8.253,
"99th_percentile_frame_rasterizer_time_millis": 74.73,
"worst_frame_rasterizer_time_millis": 74.73,
"missed_frame_rasterizer_budget_count": 2,
"frame_count": 37,

@GaryQian GaryQian added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. c: performance Relates to speed or footprint issues (see "perf:" labels) labels Dec 10, 2019
@GaryQian GaryQian self-assigned this Dec 10, 2019
@fluttergithubbot
Copy link
Contributor

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@GaryQian
Copy link
Contributor Author

This change does not really result in any testable changes, as passing Rect.zero vs _caretPrototype results in the same return values. The only difference is the internally cached values hitting/missing. I don't think this is worth adding a specific benchmark for.

final Offset startOffset = _textPainter.getOffsetForCaret(
TextPosition(offset: _selection.start, affinity: _selection.affinity),
Rect.zero,
_caretPrototype,
Copy link
Contributor Author

@GaryQian GaryQian Dec 12, 2019

Choose a reason for hiding this comment

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

This particular usage does not care what is passed in for the caretPrototype parameter. We pass in the _caretPrototype to stay consistent with the other calls of this and not mess up the cached values, avoiding redundant re-computation.

void markNeedsLayout() {
_paragraph = null;
_needsLayout = true;
_previousCaretPosition = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

clear cached values when marking as dirty.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Looks like a solid performance improvement, good catch. Can you test it?

@liyuqian liyuqian added the perf: speed Performance issues related to (mostly rendering) speed label Dec 16, 2019
@liyuqian
Copy link
Contributor

@GaryQian : a performance test for this would be nice (see *perf* in https://github.com/flutter/flutter/blob/master/dev/devicelab/manifest.yaml, where xyz_perf_abc in that yaml corresponds to a xyz_perf_abc.dart in our repo). More details of how to write a performance test is available in this doc.

@GaryQian GaryQian added this to the February 2020 milestone Dec 18, 2019
@GaryQian
Copy link
Contributor Author

Added a new perf test for textfields,

@fluttergithubbot fluttergithubbot added the c: contributor-productivity Team-specific productivity, code health, technical debt. label Dec 18, 2019
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks for doing all of the perf test work!

Copy link
Contributor

@liyuqian liyuqian left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you Gary for the performance improvement and the test that guards it! Nit request: can you please put in the commit description the performance number of your test before and after your fix? Just in case that someone regressed it in the future, they'll have some historical records to dig up.

@GaryQian GaryQian merged commit b011ea5 into flutter:master Dec 19, 2019
@liyuqian
Copy link
Contributor

@GaryQian : the original issue (#24522) complained about the GPU thread frame rasterization time, but I only see big UI thread frame build time improvement in your experiment. Do you know why GPU thread frame rasterization time doesn't have a big difference?

@anuaroa
Copy link

anuaroa commented May 20, 2020

Hi,
The version of installed Flutter is 1.17.1 (Flutter (Channel stable, v1.17.1, on Mac OS X 10.15.4 19E266, locale ru-KZ))
It's been written here https://flutter.dev/docs/development/tools/sdk/release-notes/changelogs/changelog-1.17.0 about #46720 issue, but the problem exists yet.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: text input Entering text in a text field or keyboard related problems c: contributor-productivity Team-specific productivity, code health, technical debt. c: performance Relates to speed or footprint issues (see "perf:" labels) framework flutter/packages/flutter repository. See also f: labels. perf: speed Performance issues related to (mostly rendering) speed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Caret performance is poor, high GPU time per frame.

6 participants