Skip to content

layout: Avoid potential n² comparisons when updating children of accessibility nodes - #46530

Merged
mrobinson merged 5 commits into
servo:mainfrom
alice:accessibility-set-children
Jul 17, 2026
Merged

layout: Avoid potential n² comparisons when updating children of accessibility nodes#46530
mrobinson merged 5 commits into
servo:mainfrom
alice:accessibility-set-children

Conversation

@alice

@alice alice commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Previously, we always built a pair of vecs for the new children based on the DOM children, representing the child nodes and their IDs respectively, and then compared the old and new children to set the appropriate TreeChange on each added/removed child node.

This change instead iterates over the existing child IDs and the new DOM children in parallel for as long as the two iterators match up, then removes the remaining children of the accessibility node and reconstructs the remaining children from the DOM children (reusing any existing accessibility nodes).

This also allows us to update the child_nodes vec in-place, although we can't update the children property of the AccessKit node the same way so we still need to re-create that if there is any change.

Profiles:
before: https://share.firefox.dev/4f33Hlp
after: https://share.firefox.dev/4fePVuK

Testing: No behaviour change, covered by existing tests.
Fixes: #46237

@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jul 15, 2026
@codecov-commenter

Copy link
Copy Markdown

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

@simonwuelker

Copy link
Copy Markdown
Member

Fixes: #46525

Did you mean to link #46346?

@alice

alice commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Meant to link to #46237, definitely not #46525!

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Jul 16, 2026
@mrobinson
mrobinson added this pull request to the merge queue Jul 16, 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 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 16, 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 16, 2026
alice added 5 commits July 17, 2026 10:18
Signed-off-by: Alice Boxhall <alice@igalia.com>
Signed-off-by: Alice Boxhall <alice@igalia.com>
Rather than using `zip_longest()`, just iterate over the child IDs and DOM children in parallel manually.
This doesn't move the DOM children iterator, meaning we can pick up the iterator where we left off later.

Signed-off-by: Alice Boxhall <alice@igalia.com>
Signed-off-by: Alice Boxhall <alice@igalia.com>
…()` if the child list has changed.

Signed-off-by: Alice Boxhall <alice@igalia.com>
@alice
alice force-pushed the accessibility-set-children branch from 1ff4d0f to 2851106 Compare July 17, 2026 10:40
@servo-highfive servo-highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Jul 17, 2026
@alice
alice requested a review from mrobinson July 17, 2026 10:49
@alice

alice commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

@mrobinson The last commit fixes the WPT test failure which caused it to fail the merge queue.

@mrobinson
mrobinson enabled auto-merge July 17, 2026 10:51
@mrobinson
mrobinson added this pull request to the merge queue Jul 17, 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 17, 2026
Merged via the queue into servo:main with commit f50950b Jul 17, 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 17, 2026
pull Bot pushed a commit to Haofei/servo that referenced this pull request Jul 19, 2026
…ervo#46589)

Note: this is a bit of a grab-bag of changes. Happy to split it out if
necessary.

Improvements:
- Order `counters` above `rooted_nodes` in `AccesibilityUpdate`, and add
a doc comment.
- Fix a bug in computing the number of changed nodes in an update:
- A node may be both changed and removed in a single update, which
causes it to be tracked in `changed_nodes`, but we filter out removed
nodes from the update (in fact, including them would cause a panic). The
counter needs to track the number of nodes actually sent in the update.
- Future work could avoid updating removed nodes at all, but that's out
of scope here.
- Rename fields in `AccessibilityUpdateResult` to remove redundant
`accessibility`, making tests easier to read

New tests:
- Add `accessibility-update-partial-subtree-move-and-delete.html` to
match the existing `test_accessibility_partial_subtree_move_and_delete`
in `accessibility.rs`
- Add `test_accessibility_children_of_heading_change` and
`test_accessibility_descendants_of_heading_change`, and matching
servo-wpt tests `accessibility-update-children-of-heading-change.html`
and `accessibility-update-descendants-of-heading-change.html` to test
that changing the subtree of a heading automatically causes its label to
be recomputed.
- These were added as a result of an error in servo#46530 not being picked up
by existing tests.

Testing: Existing and new tests pass.
Fixes: part of servo#46346

---------

Signed-off-by: Alice Boxhall <alice@igalia.com>
@alice
alice deleted the accessibility-set-children branch July 31, 2026 13:04
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.

Improve performance of AccessibilityNode::set_children()

5 participants