• Benjamin Beaudry's avatar
    Performance improvement of AXPosition::AsTextPosition() · 1411ed7c
    Benjamin Beaudry authored
    This change is an optimization of AsTextPosition().
    
    It's part of the larger performance improvement related to the expensive
    calls to MaxTextOffset(). AXposition::CreatePositionAtStartOfDocument()
    calls repetitively AxTextPosition() to allow converting from a tree
    position and to a text position and back, but this required calling
    MaxTextOffsetInParent() a lot.
    
    In a simple navigate-by-word situation, every call to AsTextPosition()
    would call MaxTextOffsetInParent uselessly. This change fixes it.
    
    There is no need to get the MaxTextOffset of an AXPositionInstance when
    the |text_offset_| will be positioned at the beginning of the anchor.
    We expect to position the text_offset_ of a Text Position at the
    beginning of the anchor when |text_offset_| is either invalid, already
    at 0 or less than the actual new_offset. All I did was adding a check
    for these conditions before calling MaxTextOffsetInParent().
    
    I measured the perf difference with a trace captured with WPR and
    analyzed with WPA. In both cases, the traces consist of 10 words read
    by Narrator with navigate-by-word navigation.
    
    Without patch:
      ExpandToEnclosingUnit: 2,169 ms
      CreatePositionAtStartOfDocument: 103 ms
    
    With patch:
      ExpandToEnclosingUnit: 1,851 ms
      CreatePositionAtStartOfDocument: <1 ms
    
    Bug: 928948
    Change-Id: I41d896dd25519eaba6a8c82d0ffacd3fbdedd909
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1811221
    Commit-Queue: Benjamin Beaudry <benjamin.beaudry@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@{#699478}
    1411ed7c
ax_position.h 115 KB