这是indexloc提供的服务,不要输入任何密码
Skip to content

Introduce caching mechanism during compile semantics tree monorepo and formatted version #161195

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

Merged
merged 15 commits into from
Feb 6, 2025

Conversation

chunhtai
Copy link
Contributor

@chunhtai chunhtai commented Jan 6, 2025

old pr: #150394

Pre-launch Checklist

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

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) labels Jan 6, 2025
@chunhtai chunhtai changed the title Introduce caching mechanism during compile semantics tree Introduce caching mechanism during compile semantics tree monorepo and formatted version Jan 6, 2025
@chunhtai chunhtai force-pushed the issues/150234-take2 branch from f3d4d12 to d8c7576 Compare January 7, 2025 20:37
@chunhtai chunhtai requested review from goderbauer and mdebbar January 7, 2025 21:37
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.

Some initial comments from my first read-through.

My first impression is that this approach seems more manageable and scalable than the previous one. 👍

if (!_isConfigWritable) {
_config = _config.copy();
_isConfigWritable = true;
void buildSemantics({required Set<int> usedSemanticsIds, required _SemanticsGeometry geometry}) {
Copy link
Member

Choose a reason for hiding this comment

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

What's the difference between buildSemantics and buildSemanticsSubtree? Some documentation would be helpful.

required this.blocksUserActions,
required this.explicitChildNodes,
required this.tagsForChildren,
});
Copy link
Member

Choose a reason for hiding this comment

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

For my own understanding: Why are the geometrics not part of the parent data? I thought those are passed down from the parent as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

geometric can only be determined when we know the shape of semantics tree.

the parentData is used for determine the shape of semantics tree, e.g. explicitChildNode, blocksUseractions.

basically we can't determine both geometry, parentData, and semantics tree shape in one pass.

we could merge them and make parentData mutable and do a two pass to update the parentData, but i felt that is harder to manage.

Copy link
Member

Choose a reason for hiding this comment

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

+1 to keeping parentData immutable. Maybe leave this as a comment here that geometrics are not included because we use parentData to determine the shape of the tree and geometrics can only be calculated after the shape of the tree is clear.

@Deprecated(
'This was caches for internal calculation and is no longer needed. '
'This feature was deprecated after v3.27.0-0.0.pre.',
)
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, I think we should deprecate/remove the entire elevation/thickness feature from semantics. It's unused and has never been used.

explicitChildNodes: explicitChildNodesForChildren,
tagsForChildren: tagsForChildren,
);
childSemantics.didUpdateParentData(childParentData);
Copy link
Member

@goderbauer goderbauer Jan 10, 2025

Choose a reason for hiding this comment

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

I wonder if parent data should just be a getter/setter?

@goderbauer
Copy link
Member

How good is our semantics test coverage? Did you do some manual testing on this (e.g. fire up a larger app and navigate around a bit / interact with it with a11y tools for a bit to see if everything works as expected and behaves?)

@goderbauer
Copy link
Member

Have you had a chance to look at the Google testing failures? Are we breaking something we shouldn't break?

@chunhtai chunhtai force-pushed the issues/150234-take2 branch 3 times, most recently from 4f39357 to 86a2866 Compare January 13, 2025 22:27
@chunhtai
Copy link
Contributor Author

chunhtai commented Jan 14, 2025

Have you had a chance to look at the Google testing failures? Are we breaking something we shouldn't break?

They are expected, either a color change due to more consistent id, and an actual bug fix where the test was expecting incorrect semantics tree

@chunhtai
Copy link
Contributor Author

How good is our semantics test coverage? Did you do some manual testing on this (e.g. fire up a larger app and navigate around a bit / interact with it with a11y tools for a bit to see if everything works as expected and behaves?)

I did do some manual test, but i think our test framework is quite good since it had caught a lot of corner cases

@chunhtai chunhtai requested a review from goderbauer January 14, 2025 23:17
@chunhtai chunhtai force-pushed the issues/150234-take2 branch from 3aa8c92 to 3322d3b Compare January 22, 2025 21:12
@github-actions github-actions bot added the f: material design flutter/packages/flutter/material repository. label Jan 22, 2025
@chunhtai chunhtai force-pushed the issues/150234-take2 branch from 076a4f0 to 1b32144 Compare January 23, 2025 19:04
@github-actions github-actions bot added the a: text input Entering text in a text field or keyboard related problems label Jan 23, 2025
@chunhtai chunhtai force-pushed the issues/150234-take2 branch 2 times, most recently from 31e4f89 to a9f05bb Compare January 27, 2025 18:48
@chunhtai
Copy link
Contributor Author

This is ready for review, the google test failure is due to RenderTable doesn't implment the redepthChildren method, so if two table are nested it won't be able to calculate the depth correct which lead to issues when calculate geometry transform in semantics, I will put up another pr to fix it.

@chunhtai
Copy link
Contributor Author

chunhtai commented Jan 27, 2025

table redepth pr #162282

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

@@ -2010,6 +2010,10 @@ class SemanticsNode with DiagnosticableTreeMixin {
/// See also:
///
/// * [elevation], the actual elevation of this [SemanticsNode].
@Deprecated(
'This was caches for internal calculation and is no longer needed. '
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'This was caches for internal calculation and is no longer needed. '
'This was a cache for internal calculations and is no longer needed. '

Copy link
Member

Choose a reason for hiding this comment

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

Should we also slap a deprecation notice on the (related) elevation and depth property?

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 think depth is used in dirty node compilation, but sgtm to also deprecate elevation related API

@@ -1144,11 +1144,13 @@ class RenderParagraph extends RenderBox
_semanticsInfo = text.getSemanticsInformation();
bool needsAssembleSemanticsNode = false;
bool needsChildConfigurationsDelegate = false;
bool hasTextSpan = false;
Copy link
Member

Choose a reason for hiding this comment

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

This appears to be unused?

Comment on lines 1383 to 1385
if (!kReleaseMode) {
FlutterTimeline.startSync('Semantics.updateChildren');
}
Copy link
Member

Choose a reason for hiding this comment

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

Just wondering: Is it useful that each node gets its own timeline event? They are just gonna be back-to-back in the timeline without a way to identify which node is getting processed. Should we instead just do one timeline event for the entire for loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that sounds good

}());

for (final RenderObject node in nodesToProcess) {
if (!kReleaseMode) {
Copy link
Member

Choose a reason for hiding this comment

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

Same question here and below.

}
}

for (final RenderObject node in nodesToProcess.reversed) {
Copy link
Member

Choose a reason for hiding this comment

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

Do the three for loops in this function correspond to the phases documented on _RenderObjectSemantics? If so, maybe leave a comment at the top of the function that links to that explanation there.

/// Walks the [_childrenAndElevationAdjustments] and produce semantics node for
/// each [_RenderObjectSemantics] plus the sibling nodes.
///
/// Since phase 2, 3, 4 each depends on previous step to finished updating the
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Since phase 2, 3, 4 each depends on previous step to finished updating the
/// Phase 2, 3, 4 each depends on previous step to finished updating

Comment on lines 4769 to 4770
/// Phase 1 and 2 are done in [updateChildren], Phase 3 is done in
/// [ensureGeometry], and phase 4 is done in [ensureSemanticsNode].
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this sentence all the way to the beginning just after "The _RenderObjectSemantics tree is compiled in four phases."? This is the context I was missing and asking for in a previous comment.

Copy link
Member

Choose a reason for hiding this comment

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

(Overall this is a great doc comment, though! Thank you for writing this up and providing context for future readers!)

Comment on lines +4781 to +4780
// TODO(chunhtai): Figure out what to do when incomplete fragments are asked
// to form a semantics node.
Copy link
Member

Choose a reason for hiding this comment

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

Is that supposed to happen in a real app? Shouldn't it just throw/assert if that's illegal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right now it is impossible that this can happen because i force them to merge into a _RenderObjectSemantics (by making the assumption in _collectChildMergeUpAndSiblingGroup). but that is not an ideal solution. The ideal solution is that they should form a semantics node if they are asked. but then we need a way for render object to assign geometry to those semantics node which is not possible in the current api

/// rendering subtree and forms a [_RenderObjectSemantics] tree where children
/// are stored in [_childrenAndElevationAdjustments].
///
/// This method does the following:
Copy link
Member

Choose a reason for hiding this comment

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

Maybe explicitly state again that it implements phase x of the four phases documented on [_RenderObjectSemantics]. (and also do this for the other methods that implement a phase)

Comment on lines 5265 to 5267
/// This method will in turn call the [_buildSemanticsSubtree].
///
/// This method will short-circuit itself if the [cachedSemanticsNode] is
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// This method will in turn call the [_buildSemanticsSubtree].
///
/// This method will short-circuit itself if the [cachedSemanticsNode] is
/// This method will in turn call [_buildSemanticsSubtree].
///
/// This method will short-circuit itself if the [cachedSemanticsNode]

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants