• Benoit Lize's avatar
    [base] Inline LockImpl::Lock() and LockImpl::Try(). · 7d86528b
    Benoit Lize authored
    LockImpl::Unlock() is inlined, but not LockImpl::Lock(). Separately,
    Lock() calls Try() before locking, to increase uncontended
    performance. This code is duplicated between POSIX and Windows. This
    commit:
    - Merges the two paths
    - Inlines Lock() and Try(), partly for symmetry, and partly for
      performance
    
    On a Linux Xeon "Haswell" workstation (E5-2690v4), this improves
    uncontended acquire/release pairs by 8%. These numbers are collected
    from a non-PGO build, and the impact on a PGO one is likely smaller.
    
    This was assessed by running the performance test 50 times with:
    $ out/Release-desktop/base_perftests \
        --gtest_filter="LockPerfTest.Simple" --gtest_repeat=50 \
        | grep RESULT | sed -e 's/.*= //;s/ .*//'
    
    Results are summarized below (numbers are runs/s, higher is better):
    trunk:   Mean = 4.534e+07  Standard Deviation = 6.234e+05
    This CL: Mean = 4.900e+07  Standard Deviation = 6.681e+05
    
    That is, this patch makes it 8.08% faster, and given the standard
    deviation, the difference is likely significant.
    
    Bug: 1061437
    Change-Id: Ibfb3f1f07598c22f1c9446c02e16a883bf328d20
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2386738Reviewed-by: default avatarWez <wez@chromium.org>
    Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
    Commit-Queue: Benoit L <lizeb@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#804963}
    7d86528b
lock_impl_win.cc 637 Bytes