Skip to content

layout: Avoid extra tree walks when removing accessibility nodes. - #46348

Merged
yezhizhen merged 3 commits into
servo:mainfrom
alice:accessibility-subtree-moves
Jul 14, 2026
Merged

layout: Avoid extra tree walks when removing accessibility nodes.#46348
yezhizhen merged 3 commits into
servo:mainfrom
alice:accessibility-subtree-moves

Conversation

@alice

@alice alice commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Instead of setting the TreeChange for each node in a removed subtree, just set the TreeChange for the subtree root.

Also only root the subtree root in AccessibilityData.

Testing: Adds a new test with more involved sequences of moving and removing nodes.
Fixes: #46347

@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jul 7, 2026
Comment thread components/layout/accessibility_tree.rs Outdated
Comment on lines +404 to +406
if !update.tree_changes.contains_key(&child_id) {
ids_to_remove.push(child_id);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the contains_key() check can be removed, because tree_changes has been drained by this point

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done 😅

Comment thread components/layout/accessibility_tree.rs Outdated
self.opaque_node_to_id.remove(&opaque_node);
}
for child in node.borrow().children() {
let child_id = child.borrow().id;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this can be gotten with node.child_ids(), instead of borrowing the child

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

Comment thread components/layout/accessibility_tree.rs Outdated
Comment on lines +410 to +414
debug_assert!(
update.unresolved_local_damage.is_empty(),
"Damage not empty: {:?}",
update.unresolved_local_damage
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

does this need to be debug_assert!()? seems fast?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also would be good to write a comment explaining why this is the case

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My reasoning was that I think it might not be worth crashing the tab over if there is pending damage, but it might actually be better to crash the tab in that case in case there are some subtle errors in the accessibility tree.

Comment added.

tree_id: tree.tree_id,
};

tree.remove_stale_nodes(self);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

was this reordering across the TreeUpdate initialiser intentional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah - I figured it out: we need to drop removed nodes before we filter_map() on line 902 in case we have nodes which were both changed and removed in the same update.

@servo-highfive servo-highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jul 8, 2026
Comment thread components/layout/accessibility_tree.rs Outdated
}

for id in update
let mut ids_to_remove: Vec<NodeId> = update

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
let mut ids_to_remove: Vec<NodeId> = update
let mut ids_to_remove: Vec<_> = update

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread components/layout/accessibility_tree.rs Outdated
}

// We should have resolved all damage in nodes still in the tree by this point, and any
// nodes not in the tree should have been removed from this map in the loop above.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// nodes not in the tree should have been removed from this map in the loop above.
// nodes not in the tree should have been removed from this map in the loop above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Jul 8, 2026
@alice
alice force-pushed the accessibility-subtree-moves branch from 4aeb8f7 to 60cbe13 Compare July 9, 2026 13:34
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jul 9, 2026
@mrobinson
mrobinson added this pull request to the merge queue Jul 10, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 10, 2026
@servo-highfive servo-highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jul 10, 2026
@mrobinson
mrobinson added this pull request to the merge queue Jul 10, 2026
@servo-highfive servo-highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Jul 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jul 10, 2026
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 10, 2026
@delan
delan added this pull request to the merge queue Jul 13, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 13, 2026
@servo-highfive servo-highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jul 13, 2026
alice added 3 commits July 14, 2026 10:40
Instead of setting the TreeChange for each node in a removed subtree, just set the TreeChange for the subtree root.

Also only root the subtree root in AccessibilityData.

Signed-off-by: Alice Boxhall <alice@igalia.com>
- Avoid unnecessary borrow when recursively removing children of removed nodes
- Avoid completely pointless check of empty map (!)
- Comment why we can assert that `unresolved_local_damage` is empty at the end of `drop_removed_nodes()`, and make it an `assert!()`.

Signed-off-by: Alice Boxhall <alice@igalia.com>
Signed-off-by: Alice Boxhall <alice@igalia.com>
@alice
alice force-pushed the accessibility-subtree-moves branch from 60cbe13 to 3eb0c7a Compare July 14, 2026 09:35
@servo-highfive servo-highfive removed the S-tests-failed The changes caused existing tests to fail. label Jul 14, 2026
@alice

alice commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Marked WPT test as flaky in #46497.

@jdm
jdm added this pull request to the merge queue Jul 14, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 14, 2026
@yezhizhen
yezhizhen removed this pull request from the merge queue due to a manual request Jul 14, 2026
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 14, 2026
@yezhizhen
yezhizhen added this pull request to the merge queue Jul 14, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 14, 2026
Merged via the queue into servo:main with commit bd03913 Jul 14, 2026
34 checks passed
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid rooting/marking all nodes in a removed subtree individually

5 participants