Skip to content

PoC: log fb_hasVisibleDescendants hit rate#16

Draft
Elton Carreiro (EltonCarreiro) wants to merge 1 commit into
masterfrom
poc/log-visibility-cache-hits
Draft

PoC: log fb_hasVisibleDescendants hit rate#16
Elton Carreiro (EltonCarreiro) wants to merge 1 commit into
masterfrom
poc/log-visibility-cache-hits

Conversation

@EltonCarreiro
Copy link
Copy Markdown

Summary

Pure-observability PR — adds logging to fb_hasVisibleDescendants so we can measure how often the descendant-cache shortcut actually fires on production / staging traffic. No behaviour change, just a log line.

Supersedes #15 (closed when the branch was renamed off internal shorthand).

Context

fb_isVisible (XCUIElement+FBIsVisible.m) resolves visibility through three paths:

  • Cached lookup on the snapshot's additionalAttributes.
  • A descendant-cache shortcut (fb_hasVisibleDescendants) that returns YES if any of the element's descendants is already cached as visible — skipping the expensive AX call.
  • Synchronous AX-framework IPC as the fallback.

The hypothesis is that the descendant shortcut almost never fires in the standard /source path because nothing pre-populates the cache before XML generation runs. This PR confirms or refutes that hypothesis with hard data.

Changes

WebDriverAgentLib/Categories/XCUIElement+FBIsVisible.m:

  • Adds <stdatomic.h> and FBLogger.h imports.
  • Wraps fb_hasVisibleDescendants with process-wide _Atomic NSUInteger counters for calls and hits.
  • Every 50 calls, emits one log line with calls / hits / hit rate / last-walk depth / last result.

Counters are process-wide, not per-request — they accumulate over the lifetime of the runner. Comparing hit rate before/after a workload is a simple subtract.

What we expect to see

Baseline: hit rate near 0% — confirming the shortcut is dead code in the standard /source path because the cache is never pre-populated.

If the rate turns out to be meaningfully > 0%, that's a surprise and worth investigating before we invest in pre-warming variants.

How to test

  1. Build/install on a runner.
  2. Tail Appium/WDA logs.
  3. Issue a few GET /source calls against a representative app/screen.
  4. Grep for [VisCache] and read the hit rate.

Why this as its own PR

Separated from #14 (visibility-cache pre-warming PoC) so it can land independently and give us data on master before we commit to the larger change. Safe to merge — no behaviour change, just logging.

Note on terminology

The code/comments shipped in this PR still carry some internal shorthand from the design discussion ("Tier B short-circuit", [VisCache] Tier-B stats: log prefix). That phrasing isn't meaningful outside the design conversation and will be cleaned up before this lands; please mentally substitute "descendant-cache shortcut" wherever you see it.

🤖 Generated with Claude Code

Add observability to the fb_hasVisibleDescendants short-circuit by
instrumenting cache hit/miss counters. Track calls and hits using atomic
operations, logging statistics every 50 calls to measure cache
effectiveness without impacting performance. Include last walk depth and
result in logs to aid debugging on dense screens. No behavioral changes.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant