Focus changes in web browsers make many avoidable calls to the browser

Open
#20,936 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start by reading NVDA's helpers that fetch and normalize IAccessible::accParent and accChild, and its comtypes monkey patches for QueryInterface and QueryService, as described in the issue. Reproduce the Tab-focus timing and trace the calls into the browser. Done means avoiding calls whose results are unused while preserving identical speech output and confirming the improvement with timing measurements.

Written by the indexing model from the issue text.

Description

p4 performance triaged
Brief summary

Moving the focus in web content, for example pressing Tab between links and form fields, takes NVDA around 90 ms of its own time per keypress on my test machine. Tracing the COM calls NVDA makes shows about 106 cross-process calls into the browser per Tab, and a large share of the time goes to calls whose results NVDA doesn't use:

  1. When NVDA fetches IAccessible::accParent or accChild through comtypes, comtypes converts the returned IDispatch to the "best" interface (comtypes.client._managing.GetBestInterface). This queries for IProvideClassInfo and IProvideClassInfo2 (both fail in Chromium), calls IDispatch::GetTypeInfo and makes several calls on the returned type information. NVDA then normalizes the result to IAccessible itself (IAccessibleHandler.normalizeIAccessible). In Edge, fetching a parent this way took 4 to 7 ms during a focus change, about 27 ms per Tab in total.
  2. When any COM method fails, ctypes asks the object for error information, starting with QueryInterface(ISupportErrorInfo). For QueryInterface and QueryService a failure is a normal answer and there's never error information, but for an out-of-process object the extra query is a second round trip. NVDA makes five queries that always fail in Chromium for each IAccessible NVDAObject it creates (IAccIdentity, IAccessibleTable2, IAccessibleTable, and QueryService for IHTMLElement and ITextServices), so each object creation spent about 6.5 of its 11 ms on failed queries, half of that on the error information requests.
Steps to reproduce
  1. Open a web page with links and form fields in Microsoft Edge, Google Chrome or Mozilla Firefox.
  2. Press Tab repeatedly.
  3. Measure the time from the key press to speech starting, or trace the COM calls NVDA makes.
Actual behaviour

Measured on a Windows 11 virtual machine (4 vCPUs, 8 GB), NVDA running from source on master, Edge, a simple test page with 15 focusable elements, keys sent with SendInput at 0.6 second intervals, times from the key press to the first audible audio sent to WASAPI:

  • Median about 113 ms per Tab with Eloquence (OpenEVV add-on), 108 ms with eSpeak NG.
  • Edge reports the focus change within about 6 ms; almost all of the rest is NVDA's processing, most of it waiting on calls into the browser.

In a standalone script with Edge idle, fetching accParent as NVDA does and normalizing it took 3.7 ms, compared with 0.7 ms when calling the COM method directly and then normalizing. A failed QueryInterface took 0.71 ms, compared with 0.32 ms without the error information request.

Expected behaviour

NVDA shouldn't spend time on calls whose results it doesn't use.

NVDA logs, crash dumps and other attachments

I can attach the per-call trace and the standalone timing script.

NVDA type

Running from source.

NVDA version

master at 72601bf32.

Have you tried any other versions of NVDA?

Not measured, but the same code is in 2026.3 beta 2.

Windows version

Windows 11 IoT Enterprise LTSC 2024 (26100).

Name and version of other software in use when reproducing the issue

Microsoft Edge (current stable), Mozilla Firefox 157.

Other information about your system

Virtual machine without performance/efficiency cores. Cross-process calls are slower on this machine than on typical hardware, but the proportions should be similar.

Does the issue still occur after restarting your computer?

Yes. The timings are consistent across many runs over several days.

If NVDA add-ons are disabled, is your problem still occurring?

Yes. The eSpeak NG measurements were made with no add-ons.

Does the issue still occur after you run the System Accessibility Repair Tool (COM Registration Fixing Tool in older versions) in NVDA's tools menu?

Not tried, as the cause is in NVDA's own code, described above, rather than COM registration.

I have fixes

I have two small changes ready, which I'd propose as separate pull requests: calling accParent and accChild without comtypes' conversion in NVDA's own helpers, and replacing QueryInterface and QueryService in NVDA's comtypes monkey patches with versions that don't request error information. Together they reduced Tab in Edge from about 113 ms to 66 ms, and in Mozilla Firefox 157 from about 172 ms to 86 ms, on this machine, with identical speech output in automated comparisons in Edge, Firefox, Thunderbird and LibreOffice.

Dominant language
Python
Stars
2.7k
Forks
842
Avg merge
2d 4h
Merged PRs (30d)
56

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nvaccess/nvda

All issues in nvaccess/nvda

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.