Make ObserverList iteration 10~20 times faster.
ObserverList iterators take a WeakRef to the ObserverList to detect the list being destroyed mid-iteration. ObserverList iteration doesn't need the thread-safety guarantees from base::WeakPtr, and there's rarely more than one iterator, or a couple on the stack. ObserverList iteration was identified as a performance concern as part of https://crbug.com/859155. A base::LinkedList can cater for detecting a destroy-while-iterating. This avoids the malloc() performed when the WeakRef is first dereferenced each iteration, which currently dominates iteration cost. We also reduce reference indirection, and reduce pipelining damage of atomics. Sample performance, for the given ObserverList size in Release. Values are nanoseconds to notify a single observer. Old -> New. (Old values improve with ObserverList size due to the malloc() cost being amortized over the list size). ObserverList::Unchecked 0: 22.3 -> 1.0 1: 79.6 -> 3.4 2: 61.6 -> 3.2 4: 50.5 -> 3.1 8: 41.0 -> 3.2 16: 33.6 -> 3.2 32: 30.3 -> 3.3 64: 28.8 -> 3.2 128: 28.0 -> 3.2 ObserverList<CheckedObserver> 0: 17.9 -> 0.8 1: 89.3 -> 12.9 2: 73.1 -> 14.8 4: 62.8 -> 16.0 8: 55.4 -> 18.0 16: 51.8 -> 18.3 32: 49.0 -> 18.3 64: 46.6 -> 18.3 128: 45.6 -> 18.2 Bug: 888973 Change-Id: I5edeb754e8c62d64efbbdecf617d5b33b0933688 Reviewed-on: https://chromium-review.googlesource.com/c/1242568 Commit-Queue: Trent Apted <tapted@chromium.org> Reviewed-by:Wez <wez@chromium.org> Reviewed-by:
Gabriel Charette <gab@chromium.org> Cr-Commit-Position: refs/heads/master@{#596492}
Showing
Please register or sign in to comment