-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Remove semantics geometry shortcircuit #178680
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
Remove semantics geometry shortcircuit #178680
Conversation
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.
Code Review
This pull request addresses an issue where semantics information for off-screen elements in scrollable views was not being updated correctly. The main fix involves removing a short-circuiting optimization in the semantics geometry update logic, which intentionally trades a small performance regression for correctness. The PR also includes a significant refactoring of the semantics geometry calculation, making it more systematic, and adds a new multiplyInPlace utility for matrix operations to improve performance. A regression test has been added to verify the fix. Overall, the changes are well-reasoned, but I've found a potential issue in the new geometry calculation logic.
e40cba4 to
c07f58f
Compare
chunhtai
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
QuncCccccc
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 adding the fix.
| if (kIsWeb) { | ||
| updatedTransform = data.transform?.storage ?? _kIdentityTransform; | ||
| } else if (_isTraversalChild) { | ||
| updatedTransform = _computeChildTransform( |
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.
We can move line 3940 to here as well because traversalParent is only for the traversal child transform recalculation. And then we can remove that if statement.
chunhtai
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 once the Qun's comment is addressed
|
Added a new field to store the traversal transform and moved the traversal transform calculation to before the child traversal order calculation. |
QuncCccccc
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.
The TraversalTransform change LGTM. Thanks:)
|
autosubmit label was removed for flutter/flutter/178680, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR. |
flutter/flutter@3f553f6...7b98d50 2025-11-26 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Fix for win32 embedder failing to send all alt key downs to the flutter app (#179097)" (flutter/flutter#179136) 2025-11-26 [email protected] Fix for win32 embedder failing to send all alt key downs to the flutter app (flutter/flutter#179097) 2025-11-26 [email protected] Modernize framework lints (flutter/flutter#179089) 2025-11-25 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Add framework-side hitTestBehavior support to Semantics (#178817)" (flutter/flutter#179100) 2025-11-25 [email protected] Add framework-side hitTestBehavior support to Semantics (flutter/flutter#178817) 2025-11-25 [email protected] Roll Packages from e019cf9 to cc3dca6 (1 revision) (flutter/flutter#179081) 2025-11-25 [email protected] Add tooltip windows to the windowing API alongside the window positioning logic (flutter/flutter#177404) 2025-11-25 [email protected] FlutterWindowsView::SendWindowMetrics now reliably sends the display_id (flutter/flutter#179053) 2025-11-25 [email protected] Remove semantics geometry shortcircuit (flutter/flutter#178680) 2025-11-25 [email protected] Add an assert message when OverlayEntry.remove is called twice (flutter/flutter#178163) 2025-11-25 [email protected] Roll Fuchsia Linux SDK from pOO9Jl9HTLsEmks6y... to nzuAxCJGeJbkZCTkr... (flutter/flutter#179066) 2025-11-25 [email protected] Dynamically set MinimumOSVersion in App.framework (flutter/flutter#178253) 2025-11-25 [email protected] Roll Skia from d83c30b090f4 to 925c311f4b37 (2 revisions) (flutter/flutter#179060) 2025-11-25 [email protected] Marks Linux build_android_host_app_with_module_aar to be unflaky (flutter/flutter#174864) 2025-11-25 [email protected] Marks Linux_mokey complex_layout__start_up to be unflaky (flutter/flutter#174865) 2025-11-25 [email protected] Manual Dart SDK roll to 3.11.0-169.0.dev (flutter/flutter#179054) 2025-11-25 [email protected] Bump Dart to 3.9 (flutter/flutter#179041) 2025-11-25 [email protected] Roll Skia from e298c2f93ebf to d83c30b090f4 (2 revisions) (flutter/flutter#179058) 2025-11-24 [email protected] updated licenses_cpp readme (flutter/flutter#178874) 2025-11-24 [email protected] Roll Skia from 43d2020be565 to e298c2f93ebf (5 revisions) (flutter/flutter#179046) 2025-11-24 [email protected] Refactor `_isLabel` method in `stepper.dart` to use `any` for better readablity (flutter/flutter#178909) 2025-11-24 49699333+dependabot[bot]@users.noreply.github.com Bump actions/checkout from 5 to 6 in the all-github-actions group (flutter/flutter#179049) 2025-11-24 [email protected] Disposes test restoration manager when accessed by bindings (flutter/flutter#176519) 2025-11-24 [email protected] [ Widget Preview ] Always generate scaffold under `$TMP` (flutter/flutter#179039) 2025-11-24 [email protected] Roll Packages from e67b6be to e019cf9 (9 revisions) (flutter/flutter#179035) 2025-11-24 [email protected] Update CHANGELOG.md for Flutter 3.38.3 (flutter/flutter#178935) 2025-11-24 [email protected] Remove unnecessary `String.valueOf` in `SettingsChannel.java` (flutter/flutter#178590) 2025-11-24 [email protected] Roll pub manually, pick up flutter_lints in examples/api (flutter/flutter#179030) 2025-11-24 [email protected] Roll Dart SDK from 24cc9a740bd3 to afca43095efa (1 revision) (flutter/flutter#179019) 2025-11-24 [email protected] Pass EXCLUDED_ARCHS from Xcode project to xcodebuild for macOS builds (flutter/flutter#176948) 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] 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
Fixes flutter#173097 The semantics flush is ~200 μs slower with the shortcuircut removed + flutter#177477 (which reduces the time increase by ~ 100 μs, from 876 μs to 773 μs) I tried to introduce caching in [a different patch](https://github.com/flutter/flutter/compare/master...LongCatIsLooong:semantics-geometry?expand=1) but that patch is more risky and still needs a cleanup. 773 μs doesn't seem bad considering there were little to no geometry updates between frames before the fix. Introducing cache currently only improves `Semantics.ensureGeometry` by less than 100 μs and is much more risky / harder to ensure the correctness. ### BEFORE ``` [bench_material3_scroll_semantics] name: bench_material3_scroll_semantics SEMANTICS: (samples: 98 clean/2 outliers/100 measured/300 total) | average: 567.0510204081633 μs | outlier average: 799 μs | outlier/clean ratio: 1.4090442856885785x | noise: 13.95% Semantics.updateChildren: (samples: 91 clean/9 outliers/100 measured/300 total) | average: 58.9010989010989 μs | outlier average: 199.88888888888889 μs | outlier/clean ratio: 3.3936359867330017x | noise: 82.78% Semantics.ensureGeometry: (samples: 95 clean/5 outliers/100 measured/300 total) | average: 95.46315789473684 μs | outlier average: 299 μs | outlier/clean ratio: 3.1320983570404675x | noise: 64.29% Semantics.ensureSemanticsNode: (samples: 100 clean/0 outliers/100 measured/300 total) | average: 78.59 μs | outlier average: 78.59 μs | outlier/clean ratio: 1x | noise: 80.86% drawFrameDuration: (samples: 98 clean/2 outliers/100 measured/300 total) | average: 1685.6938775510205 μs | outlier average: 2000 μs | outlier/clean ratio: 1.1864550418285935x | noise: 7.77%``` ``` ### AFTER (with this and flutter#177477) ``` [bench_material3_scroll_semantics] name: bench_material3_scroll_semantics SEMANTICS: (samples: 91 clean/9 outliers/100 measured/300 total) | average: 773.1098901098901 μs | outlier average: 1000 μs | outlier/clean ratio: 1.2934771793669069x | noise: 10.65% Semantics.updateChildren: (samples: 94 clean/6 outliers/100 measured/300 total) | average: 48.648936170212764 μs | outlier average: 200 μs | outlier/clean ratio: 4.111086813907719x | noise: 102.15% Semantics.ensureGeometry: (samples: 95 clean/5 outliers/100 measured/300 total) | average: 239.55789473684212 μs | outlier average: 399.6 μs | outlier/clean ratio: 1.6680727656208807x | noise: 22.05% Semantics.ensureSemanticsNode: (samples: 99 clean/1 outliers/100 measured/300 total) | average: 194.5151515151515 μs | outlier average: 400 μs | outlier/clean ratio: 2.0563950771148156x | noise: 31.31% drawFrameDuration: (samples: 95 clean/5 outliers/100 measured/300 total) | average: 1775.8315789473684 μs | outlier average: 2099.6 μs | outlier/clean ratio: 1.1823193285280729x | noise: 7.56% ``` ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Fixes flutter#173097 The semantics flush is ~200 μs slower with the shortcuircut removed + flutter#177477 (which reduces the time increase by ~ 100 μs, from 876 μs to 773 μs) I tried to introduce caching in [a different patch](https://github.com/flutter/flutter/compare/master...LongCatIsLooong:semantics-geometry?expand=1) but that patch is more risky and still needs a cleanup. 773 μs doesn't seem bad considering there were little to no geometry updates between frames before the fix. Introducing cache currently only improves `Semantics.ensureGeometry` by less than 100 μs and is much more risky / harder to ensure the correctness. ### BEFORE ``` [bench_material3_scroll_semantics] name: bench_material3_scroll_semantics SEMANTICS: (samples: 98 clean/2 outliers/100 measured/300 total) | average: 567.0510204081633 μs | outlier average: 799 μs | outlier/clean ratio: 1.4090442856885785x | noise: 13.95% Semantics.updateChildren: (samples: 91 clean/9 outliers/100 measured/300 total) | average: 58.9010989010989 μs | outlier average: 199.88888888888889 μs | outlier/clean ratio: 3.3936359867330017x | noise: 82.78% Semantics.ensureGeometry: (samples: 95 clean/5 outliers/100 measured/300 total) | average: 95.46315789473684 μs | outlier average: 299 μs | outlier/clean ratio: 3.1320983570404675x | noise: 64.29% Semantics.ensureSemanticsNode: (samples: 100 clean/0 outliers/100 measured/300 total) | average: 78.59 μs | outlier average: 78.59 μs | outlier/clean ratio: 1x | noise: 80.86% drawFrameDuration: (samples: 98 clean/2 outliers/100 measured/300 total) | average: 1685.6938775510205 μs | outlier average: 2000 μs | outlier/clean ratio: 1.1864550418285935x | noise: 7.77%``` ``` ### AFTER (with this and flutter#177477) ``` [bench_material3_scroll_semantics] name: bench_material3_scroll_semantics SEMANTICS: (samples: 91 clean/9 outliers/100 measured/300 total) | average: 773.1098901098901 μs | outlier average: 1000 μs | outlier/clean ratio: 1.2934771793669069x | noise: 10.65% Semantics.updateChildren: (samples: 94 clean/6 outliers/100 measured/300 total) | average: 48.648936170212764 μs | outlier average: 200 μs | outlier/clean ratio: 4.111086813907719x | noise: 102.15% Semantics.ensureGeometry: (samples: 95 clean/5 outliers/100 measured/300 total) | average: 239.55789473684212 μs | outlier average: 399.6 μs | outlier/clean ratio: 1.6680727656208807x | noise: 22.05% Semantics.ensureSemanticsNode: (samples: 99 clean/1 outliers/100 measured/300 total) | average: 194.5151515151515 μs | outlier average: 400 μs | outlier/clean ratio: 2.0563950771148156x | noise: 31.31% drawFrameDuration: (samples: 95 clean/5 outliers/100 measured/300 total) | average: 1775.8315789473684 μs | outlier average: 2099.6 μs | outlier/clean ratio: 1.1823193285280729x | noise: 7.56% ``` ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Fixes #173097
The semantics flush is ~200 μs slower with the shortcuircut removed + #177477 (which reduces the time increase by ~ 100 μs, from 876 μs to 773 μs) I tried to introduce caching in a different patch but that patch is more risky and still needs a cleanup.
773 μs doesn't seem bad considering there were little to no geometry updates between frames before the fix. Introducing cache currently only improves
Semantics.ensureGeometryby less than 100 μs and is much more risky / harder to ensure the correctness.BEFORE
AFTER (with this and #177477)
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.