PoC: pre-warm visibility cache + diagnostic logging#14
Draft
Elton Carreiro (EltonCarreiro) wants to merge 1 commit into
Draft
PoC: pre-warm visibility cache + diagnostic logging#14Elton Carreiro (EltonCarreiro) wants to merge 1 commit into
Elton Carreiro (EltonCarreiro) wants to merge 1 commit into
Conversation
Instrument and add optional pre-warming of the visibility cache to improve performance of `fb_hasVisibleDescendants` short-circuiting (Tier B heuristic). When `warm_visibility_cache` querystring is truthy, walk leaf nodes of the snapshot tree before XML generation to populate the visibility cache, allowing parent nodes to short-circuit without expensive synchronous AX framework IPC. Add diagnostic logging to measure Tier B hit rates. Changes are backward compatible; warming is disabled by default. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/sourceXML generation pays a synchronous AX-framework IPC per element when computing thevisibleattribute.fb_isVisible(XCUIElement+FBIsVisible.m) resolves visibility through three paths:additionalAttributes[FB_XCAXAIsVisibleAttribute]from the snapshot.fb_hasVisibleDescendantswalks_allDescendants; if any descendant is already cached as visible, returns YES without an AX call.XCAXClient.attributesForElement:attributes:. The expensive one.Today nothing pre-populates the cache before XML generation, so the cached lookup always misses on a fresh snapshot. The descendant shortcut also misses because none of the descendants are cached either — every node falls through to the AX IPC.
This PR adds an opt-in pre-warm pass that resolves visibility on the leaves of the snapshot tree before XML generation. Internal nodes then benefit from the descendant shortcut during XML generation (their
_allDescendantswalk finds at least one cached-visible leaf and short-circuits), skipping their own AX IPC.Changes
FBXMLGenerationOptions: new tri-statewarmVisibilityCache: NSNumber?property +withWarmVisibilityCache:builder.FBDebugCommands.handleGetSourceCommand: parses?warm_visibility_cache=true|1|yes(case-insensitive truthy), threads throughFBXMLGenerationOptions.FBXPath.xmlStringWithRootElement:options:: when the flag is truthy, calls the new private+warmVisibilityCacheForSnapshot:which recurses to leaves and resolveswdVisibleon each. Logs[VisCache] (FBXPath) Warmed visibility cache in N.NNNs.XCUIElement+FBIsVisible.fb_hasVisibleDescendants: instrumented with process-wide_Atomiccounters; logs hit-rate stats every 50 calls. Always-on — runs regardless of the warming flag, so cold and warmed runs are both measurable.Why leaves-only
The descendant shortcut looks for any cached-visible descendant, not specifically a child or a leaf. Warming leaves alone guarantees every internal node with at least one visible leaf in its subtree will short-circuit. AX-IPC cost is unchanged (same nodes still pay it: only those whose entire subtree is invisible), but we avoid one full O(n²)
_allDescendantssweep that warming internal nodes would cost.How to validate
GET /sourcewith no querystring. Tail logs for the stats line — expect near-0% hit rate.GET /source?warm_visibility_cache=true. Confirm[VisCache] (FBXPath) Warmed…appears, then watch hit rate climb on subsequent stats logs.! Fetching of XC_kAXXCAttributeIsVisible took N.NNswarnings per request.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.Out of scope (deferred)
FBConfiguration.warmVisibilityCacheInPageSourceflag — promote only if results justify.ios-agent.attributes:(collapses N IPCs into 1).🤖 Generated with Claude Code