Skip to content

Fix freeze when accessibility reads a long history - #31432

Open
xboxfanj wants to merge 1 commit into
telegramdesktop:devfrom
xboxfanj:accessible-elements-cache
Open

xboxfanj wants to merge 1 commit into
telegramdesktop:devfrom
xboxfanj:accessible-elements-cache

Conversation

@xboxfanj

@xboxfanj xboxfanj commented Oct 9, 2026

Copy link
Copy Markdown

Querying the message list through accessibility freezes the app for seconds once a few thousand messages are loaded. HistoryInner::accessibleElements() walks every history block and builds a new vector on each call. accessibilityChildCount(), accessibilityChildIdentity(), accessibilityChildState() and the other per-row methods each call it, and accessibilityUnreadBarIndex() builds it once more. Ui::Accessible::Item asks several of these for every row while the platform lists the children, so listing n rows costs O(n²) on the main thread. HistoryView::ListWidget got the same parallel implementation in #30948 and has the same cost.

To fix this, this PR keeps the built list until the rows change. HistoryInner drops it in viewRemoved() and recountHistoryGeometry(), and HistoryView::ListWidget in viewReplaced() and updateItemsGeometry(), so the list never holds a destroyed view. The unread bar index is cached for the current bar element. Methods that move focus or scroll still take a copy, because scrolling can load or unload messages while they run.

Tested on macOS 26 (arm64) with v7.2.9 (the patch applies to dev as is), in a group with 6705 loaded messages, querying the message list with the macOS accessibility API:

before after
AXChildren count 5.0 s 2 ms
AXChildren 6.1 s 39 ms
role, description and selection of the newest 5000 rows 3.5 s 0.19 s

The rows returned match before and after: the same count, and the same hash over the role, description and selection of the newest 5000 rows.

To reproduce, load a few thousand messages in a chat and ask its message list for AXChildren. Any client that lists the window's children does this. With an app switcher reading windows in the background (AltTab 11.1.0), the app froze for about 2 s every few seconds while typing.

@CLAassistant

CLAassistant commented Oct 9, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@RonaldKepken

Copy link
Copy Markdown

Looks great! That's one big performance improvement 👌🏻

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants