• Ethan Jimenez's avatar
    Optimize AXRange's AsForwardRange and GetScreenRects · 97600fa9
    Ethan Jimenez authored
    1. Refactoring most of `AXRange::AsForwardRange` logic into a new static
       helper `CompareEndpoints` that determines between two `AXPosition`
       which one should be the start when using `AXRange::Iterator`.
    
       This helper is also used in `ITextRangeProvider::MoveEndpointByUnit`,
       in order to avoid more expensive comparisons of text positions.
    
    2. As part of the `AsForwardRange` refactor, `CompareEndpoints` was
       optimized by avoiding even more text position comparisons.
    
    3. Removing a pair of unnecessary calls to `CreateParentPosition` in
       `AXRange::GetScreenRects` when we iterate over inline text boxes.
    
       `CreateParentPosition` for a text position computes the max text
       offset of every subtree before the child node containing the given
       position, doing this sequentially for inline text boxes within the
       same parent node would result in n^2 calls to `MaxTextOffset`.
    
    4. Before introducing these optimizations, the percentage of how much
       the subroutines above constituted a call to `GetScreenRects` were:
    
       AXRange::GetScreenRects                  Weight %
       |- AXPosition::CreateParentPosition       ~20.81%
       |- AXRange::Iterator::begin               ~18.28%
       |- AXRange::Iterator::end                 ~‭18.41%
    
       ITextRangeProvider::MoveEndpointByUnit   Weight %
       |- AXPosition::operator<                  ~10.01%‬
    
       After introducing this change's optimizations, the weight of every
       method listed was reduced to ~0% in their respective call stacks.
    
    Bug: 928948
    Change-Id: I0584e74af8327fdc3855a4d80060030998b7de95
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1928320
    Commit-Queue: Ethan Jimenez <ethavar@microsoft.com>
    Reviewed-by: default avatarKurt Catti-Schmidt <kschmi@microsoft.com>
    Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#718411}
    97600fa9
ax_range.h 14.3 KB