Open Bug 2065457 Opened 3 months ago Updated 1 month ago

Updating aria-selected while a tabpanel is removed from the DOM destroys ~5,700 accessibles at ~48µs each, blocking the main thread ~280ms per tab switch

Categories

(Core :: Disability Access APIs, defect)

Firefox 154
Desktop
Windows 11
defect

Tracking

()

UNCONFIRMED
Performance Impact ?

People

(Reporter: frank, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: perf, perf:responsiveness)

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36

Steps to reproduce:

Precondition: the accessibility engine must be instantiated. With it off, everything below costs 0 ms. On the affected user's machine about:support reports Activated: true, Accessibility Instantiator: UIAUTOMATION — a UI Automation client, not a screen reader, so the user had not knowingly enabled anything. Reproduced for analysis with accessibility.force_disabled = -1.

Steps to reproduce
Load a page with a tab widget where one tab panel contains a few thousand elements (~5,500 in the profiled case), nested as a widget toolkit nests them — panels within panels, ten-plus levels, focusable containers throughout.
Switch tabs. The outgoing panel is removed from the DOM, the incoming one inserted, and aria-selected is updated on the two tab buttons in the same tick.

Actual results:

he attached profile contains three consecutive switches. Each is a single busy run inside the refresh driver tick:

switch teardown markers busy run
1 5,693 276 ms
2 5,693 285 ms
3 5,693 280 ms

18,783 DocAccessible::ContentRemovedNode and 18,617 DocAccessible::ShutdownChildrenInSubtree in total — one per DOM node of the outgoing panel, ~48 µs each.

Top self time inside the first run (278 ms busy):

ms function
16.0 nsIFrame::IsFocusable
15.6 a11y::aria::MapToState
14.6 nsRoleMapEntry::ARIARoleString
9.5 span_details::operator==
8.0 PLDHashTable::ComputeKeyHash
7.5 BinarySearchIf(nsRoleMapEntry[131] …)
6.0 Compare(nsTStringRepr…)
6.0 AttrArray::GetAttr

27 % of the run is in explicitly a11y::-named frames; the remainder is the attribute lookup, atom comparison and hashtable machinery those calls drive.

The three interleaved switches in the opposite direction — which insert the same panel rather than remove it — produce ~100 ms runs with 4 % accessibility work, so this is not the cost of a DOM swap in general.

Expected results:

Removing a subtree from the document should not cost ~48 µs per element. In particular ARIARoleString + the binary search over the 131-entry role map re-derives each element's ARIA role while its accessible is being destroyed, which looks like work the teardown path does not need.

The trigger is specifically the aria-selected write

Suppressing only that attribute update, leaving role="tablist", role="tab" and role="tabpanel" in place, takes the same switch from 245 ms to 18 ms. No scheduling avoids it — written inline it coincides with the panel's removal; deferred by one macrotask it coincides with the incoming panel's insertion (213–280 ms); on requestIdleCallback with both (242–260 ms).

The following were each removed independently with no effect, so the cost is not simply "a lot of ARIA in the document": role="none" (3,639 attributes), role="img" + role="group" (1,696), all 645 aria-labelledby, 25 control roles (button/checkbox/spinbutton/textbox), and role="tabpanel" itself.

Possibly the same underlying defect as bug 2057395

That bug describes deeply nested trees of focusable items and attributes the cost to Accessible.cpp#744 walking ancestors calling State(), which calls ImplicitState() on each ancestor, which calls State() on all ancestors again.

The hot functions here are that same State() chain — MapToState, ARIARoleString, IsFocusable — and the DOM matches its precondition: panels nested ten-plus levels deep with focusable containers at most levels. Filing separately because the trigger and the affected operation differ, but if the ancestor walk is the shared cause, fixing it may resolve both.

Comparisons
Chrome with --force-renderer-accessibility, same page: 0 ms
The same application on an older build that does not put ARIA attributes on every element: 16 ms for the identical DOM swap, accessibility engine on
Firefox with the accessibility engine disabled: 0 ms
Reproduction

A standalone HTML case (two tabs, ~5,000 flat divs, detach/attach + aria-selected flip) did not reproduce; in light of bug 2057395 the missing ingredient is likely nesting depth and focusable ancestors rather than element count. The attached profile reproduces deterministically — three switches in one recording, 276/285/280 ms.

Blocks: a11yperf
Performance Impact: --- → ?
Component: Untriaged → Disability Access APIs
OS: Unspecified → Windows 11
Product: Firefox → Core
Hardware: Unspecified → Desktop
See Also: → 2057395
Summary: Updating aria-selected while a tabpanel is removed from the DOM destroys ~5,700 accessibles at ~48µs each, blocking the main thread ~250ms per tab switch → Updating aria-selected while a tabpanel is removed from the DOM destroys ~5,700 accessibles at ~48µs each, blocking the main thread ~280ms per tab switch

Correction to the auto-filled User Agent line in comment 0: that is the browser this report was filed from, not where the bug occurs. The bug is in Firefox 154.0 on Windows 11, which is also what the attached profile was captured in. Chrome appears in the report only as the comparison case — the same page with --force-renderer-accessibility costs 0 ms there.

Severity: -- → S3

Not having a test case or even a test site to test against here will make it pretty hard to diagnose this bug or verify whether we've actually fixed it. Without that, I'd say this bug is not actionable.

panels nested ten-plus levels deep with focusable containers at most levels

Why are the containers focusable? In the bug 2057395 tree case, this was because the tree items were focusable, which is expected for tree items. But I'm having trouble understanding why there would be multiple focusable containers above a tab panel or tablist.

Thanks — both fair. Taking the second point first, since I was imprecise in the report.

Measured from the real page, the heavy tabpanel contains 5,292 elements, 961 of which have tabindex (none -1), and all 961 have non-visible overflow — they are scroll containers. That is why they are focusable: nested panels in a desktop-style widget toolkit each get their own overflow, and a scrollable element is keyboard-focusable so it can be scrolled with the arrow keys. nsIFrame::IsFocusableDueToScrollFrame appears in the attached profile, which fits.

To correct comment 0: the focusable containers are inside the tabpanel, not above it — only 3 focusable ancestors sit above the tabpanel and 2 above the tablist. Nesting is ~24 levels deep rather than "ten-plus", giving ~5 focusable ancestors above each leaf. So it is not tree items being focusable as in bug 2057395, though the ancestor chain is similar in shape.

On the test case: I have not managed to build a standalone one. Three attempts now — flat divs, deeply nested divs, and finally a DOM built to the measured proportions above (5,305 elements, 1,105 focusable overflow:hidden containers with role="group", depth 24) — all measure 0 ms in both configurations with the accessibility engine forced on. So whatever the trigger needs, it is not just element count, nesting depth and focusable scroll containers. That may be a useful negative result in itself.

What I can offer instead is a test site: the application that produces the attached profile, hosted at a public URL, where a tab switch reproduces the ~280 ms stall every time and a checkbox toggles the aria-selected write on and off so the difference is visible in one session. Would that work for you? I can have it up shortly.

(In reply to Frank Boettcher from comment #4)

What I can offer instead is a test site: the application that produces the attached profile, hosted at a public URL, where a tab switch reproduces the ~280 ms stall every time and a checkbox toggles the aria-selected write on and off so the difference is visible in one session. Would that work for you? I can have it up shortly.

It would be helpful, yes, but I'm guessing you can't host it forever and I can't give you an estimate at this stage as to when we'll be able to look into this in depth. If it can't be attached as a zip file or similar, it might be best to hold off on that until we fix bug 2057395, after which we can re-evaluate the impact here.

I uploaded the profile from comment 0 to make it easier to analyse:
https://share.firefox.dev/4irkYGN

(In reply to James Teh [:Jamie] from comment #5)

(In reply to Frank Boettcher from comment #4)

What I can offer instead is a test site: the application that produces the attached profile, hosted at a public URL, where a tab switch reproduces the ~280 ms stall every time and a checkbox toggles the aria-selected write on and off so the difference is visible in one session. Would that work for you? I can have it up shortly.

It would be helpful, yes, but I'm guessing you can't host it forever and I can't give you an estimate at this stage as to when we'll be able to look into this in depth. If it can't be attached as a zip file or similar, it might be best to hold off on that until we fix bug 2057395, after which we can re-evaluate the impact here.

Hello James,

As requested, here's the link to the deployed version of the test app: https://bugzilla2065457-gxdwe2h4ccadftcm.canadacentral-01.azurewebsites.net/

Best Regards,
Alaa

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: