-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Pass _caretPrototype to prevent cache miss #46720
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
Conversation
|
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. |
|
This change does not really result in any testable changes, as passing |
| final Offset startOffset = _textPainter.getOffsetForCaret( | ||
| TextPosition(offset: _selection.start, affinity: _selection.affinity), | ||
| Rect.zero, | ||
| _caretPrototype, |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
justinmc
left a comment
There was a problem hiding this 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?
|
@GaryQian : a performance test for this would be nice (see |
|
Added a new perf test for textfields, |
justinmc
left a comment
There was a problem hiding this 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!
liyuqian
left a comment
There was a problem hiding this 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 : 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? |
A continuation of flutter#46720
|
Hi, |
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.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.
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,