Using caching with AutomationElements doesn't give me speedup - intended or misused?

I am trying to increase the speed of some UI automation operations. I came across a (not very good) documented caching capability.

From what I understand, the whole operation (if you have a large GUI tree) is so slow, because for every function call there must be a process change (it’s kind of like switching to kernel mode, I guess, in speed!). So .. caching comes in.

Just tell the function to cache the element and its children, and then work on it lightning fast. (From what I understand, you only have one change of context and collect all the data you need at a time.)

Good idea, but ... for me it's as slow as an undisclosed variation. I wrote a simple test code and did not see an improvement.

AutomationElement ae; // element whose siblings are to be examined, thre are quite a few siblings
AutomationElement sibling;

#region non-cached
watch.Start();
for (int i = 0; i < 10; ++i)
{
    sibling = TreeWalker.RawViewWalker.GetFirstChild(TreeWalker.RawViewWalker.GetParent(ae));
    while (sibling != null)
    {
        sibling = TreeWalker.RawViewWalker.GetNextSibling(sibling);
    }
}
watch.Stop();
System.Diagnostics.Debug.WriteLine("Execution time without cache: " + watch.ElapsedMilliseconds + " ms.");
#endregion

#region cached
watch.Reset();
watch.Start();

CacheRequest cacheRequest = new CacheRequest();
cacheRequest.TreeScope = TreeScope.Children | TreeScope.Element; // for testing I chose a minimal set
AutomationElement parent;

for (int j = 0; j < 10; ++j)
{
    using (cacheRequest.Activate())
    {
        parent = TreeWalker.RawViewWalker.GetParent(ae, cacheRequest);
    }
    int cnt = parent.CachedChildren.Count;
    for (int i = 0; i < cnt; ++i)
    {
        sibling = parent.CachedChildren[i];
    }
}
watch.Stop();
System.Diagnostics.Debug.WriteLine("Execution time parentcache: " + watch.ElapsedMilliseconds + " ms.");
#endregion

Customization: you get the item and want to check all of its (many) siblings. Both implementations are given without and with a cache.

Exit (debug mode): Execution time without cache: 1130 ms. Parentcache runtime: 1271 ms.

Why is this not working? How to improve?

Thanks for any ideas !!!

+3
source share
2 answers

, , , . , ( ) . , . . ComboBox 100 - , , - . , - , , ... , . , , , .current 20 , .

0

, , ( , - .) , , , parent.CachedChildren, , . , .

, , , , .

+2

All Articles