Skip to content

perf(wda): a lookup reads the page source without visible and accessible - #266

Merged
omnarayan merged 1 commit into
devicelab-dev:mainfrom
luka-vladika-happening-xyz:perf/wda-lookup-source-without-visible
Nov 9, 2026
Merged

omnarayan merged 1 commit into
devicelab-dev:mainfrom
luka-vladika-happening-xyz:perf/wda-lookup-source-without-visible

Conversation

@luka-vladika-happening-xyz

@luka-vladika-happening-xyz luka-vladika-happening-xyz commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

On a real iPhone the WDA driver falls back to GET /source whenever WebDriverAgent's own query does not settle a lookup: a selector that matches nothing yet (every poll of an optional step or a when: visible), a text whose first match is off screen, and always for relative selectors, index:, a size, copyTextFrom and the keyboard checks.

WebDriverAgent computes visible and accessible for every element of that tree, visible with an accessibility call each. The page-source matcher does not decide on either: it keeps an element by its bounds (FilterOutOfBounds); visible only picked the "visible=false but within the viewport" note, and accessible is not read. WebDriverAgent's /source can leave attributes out (excluded_attributes, FBDebugCommands.m); Appium's XCUITest driver exposes the same thing as its pageSourceExcludedAttributes setting, for the same reason.

This PR asks for those reads with excluded_attributes=visible,accessible. Hierarchy() still reads the whole source, so the report and the hierarchy command keep every attribute. A match found in such a source no longer carries the note above.

Measured with WebDriverAgent 11.4.1 on a real app's heavy screen (a page source of about 830 KB), raw GET /source calls in alternating order:

whole without accessible without visible without both
iPhone 17, iOS 27.0.1 21–28 s (median 25.0, 7 reads) 21–22 s 4.7–7.3 s 2.4–4.1 s (median 2.4, 7 reads)
iPhone 13 Pro Max, iOS 18.4.1 median 28.7 s (4 reads) median 3.7 s (4 reads)

The same with WebDriverAgent 16.17.5 (the version this repository bundles under drivers/ios/WebDriverAgent): on an iPhone 14 Pro (iOS 27.2), a heavy screen of the same kind (a page source of about 830 KB), raw GET /source alternated between 11.4.1 and 16.17.5 installed side by side, ten reads each: whole, 25.2 s on 11.4.1 and 24.9 s on 16.17.5; with excluded_attributes=visible,accessible, 2.2 s and 2.0 s. A lighter screen (about 180 KB): 7.0 s whole on both, 0.4 s trimmed on both. The attribute computations are the same code in both versions (XCUIElement+FBIsVisible.m is unchanged), so the gain does not depend on which WebDriverAgent the driver talks to.

And two flows on the iPhone 17, our build of v1.1.30 (with #263) without and with this change, four runs each in alternating order, all passed (medians):

before after
a flow with checks by text whose first match is off screen, and four lookups of absent elements 273 s (19 page sources, 182 s in them) 129 s (50 page sources, 25 s in them)
a flow that opens a heavy screen and scrolls to an optional element 139 s (12 page sources, 89 s) 96 s (38 page sources, 33 s)
a check by text whose first match is off screen 21.3 s 4.4 s
runFlow: when: visible on an id that is not there 22.0 s 4.2 s

On an iPhone 13 Pro Max (iOS 18.4.1), the same series: the first flow 313 → 173 s; the second unchanged (115 → 118 s), since its lookups of absent elements there ended at their steps' timeouts either way.

There are more page sources after the change because each poll of a waiting step is cheap now, so a step looks more often within the same timeout.

Tested with a fake WebDriverAgent (lookup_source_test.go: a lookup asks for the trimmed source and still matches, and Hierarchy() asks for the whole one). go test ./pkg/driver/wda/ passes; golangci-lint v2.13.2: 0 issues.

A lookup that WebDriverAgent's own query does not settle falls back to the
page source (GET /source), and so do relative selectors, an index, a size,
copyTextFrom and the keyboard checks. WebDriverAgent computes `visible` and
`accessible` for every element of that tree, `visible` with an accessibility
call each, and the page-source matcher reads neither: it keeps an element by
its bounds (FilterOutOfBounds), and `visible` only chose a report note.

Those reads now ask for the source with excluded_attributes=visible,accessible,
which WebDriverAgent supports on /source (FBDebugCommands). On an iPhone 17
(iOS 27) on a screen of a few thousand elements the source took 23 s whole
and 2.5 s without the two. Every element of such a source parses as displayed,
so a match it finds no longer carries the "visible=false but within the
viewport" note. Hierarchy() still reads the whole source, for the report and
the hierarchy command.
@codecov

codecov Bot commented Nov 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@omnarayan
omnarayan merged commit 7c7e135 into devicelab-dev:main Nov 9, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants