Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Optimistically update ref counts #7248
Profiling has shown that a non trivial (~1%) of CPU time on gRPC
This changes from using compareAndSet to getAndAdd, which emits a
On a highly contended machine, this can be about 2x faster.
There is a downside to the new approach. The ref counters can
Time 1 Thread 1: obj.retain(INT_MAX - 1)
Previously Thread 2 would always succeed and Thread 1 would always
There are a few reasons why I think this is okay:
Added a benchmark. The results show that under higher contention, the new version is much faster. As the amount of work done between retain and release goes up, contention goes down and they even out.
In general this is playing "fast an loose" with the atomics. I'm guessing it is unlikely to be an issue and most folks will just use the