Avoid atomic operation on the last refcount
Summary: There's no need in the atomic refcount decrement from 1->0, because we're the last live reference and using it to bump 1->2 is already undefined behavior. Added benchmark: Before: ``` stepan@devvm329:~/fbsource/fbcode$ buck-out/opt/gen/folly/io/test/iobuf_benchmark --bm_min_usec=1000000 ============================================================================ folly/io/test/IOBufBenchmark.cpp relative time/iter iters/s ============================================================================ createAndDestroy 36.35ns 27.51M cloneOneBenchmark 40.40ns 24.75M cloneOneIntoBenchmark 27.03ns 37.00M cloneBenchmark 42.23ns 23.68M cloneIntoBenchmark 28.35ns 35.27M moveBenchmark 15.20ns 65.79M copyBenchmark 35.00ns 28.57M cloneCoalescedBaseline 334.59ns 2.99M cloneCoalescedBenchmark 660.01% 50.69ns 19.73M takeOwnershipBenchmark 50.57ns 19.78M ============================================================================ ``` After: ``` stepan@devvm329:~/fbsource/fbcode$ buck-out/opt/gen/folly/io/test/iobuf_benchmark --bm_min_usec=1000000 ============================================================================ folly/io/test/IOBufBenchmark.cpp relative time/iter iters/s ============================================================================ createAndDestroy 30.04ns 33.29M cloneOneBenchmark 41.27ns 24.23M cloneOneIntoBenchmark 26.37ns 37.92M cloneBenchmark 43.91ns 22.77M cloneIntoBenchmark 28.49ns 35.10M moveBenchmark 15.50ns 64.52M copyBenchmark 35.85ns 27.89M cloneCoalescedBaseline 318.49ns 3.14M cloneCoalescedBenchmark 643.69% 49.48ns 20.21M takeOwnershipBenchmark 45.15ns 22.15M ============================================================================ ``` Reviewed By: yfeldblum, davidtgoldblatt Differential Revision: D14715579 fbshipit-source-id: 3c0373b8423dda680920860979cfa240bf3d8d7a
Showing
Please register or sign in to comment