Commit 85bc0de2 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

shrink SingletonRelaxedCounter inline slow path

Summary: Persuade the compiler to emit a tail call in the `SingletonRelaxedCounter` inline slow path.

Differential Revision: D27383131

fbshipit-source-id: 6f58b1eb23477c00221515d7d6e55a91668f7c84
parent 7426f02a
......@@ -141,8 +141,7 @@ class SingletonRelaxedCounter {
}
};
FOLLY_ALWAYS_INLINE static void mutate(Signed v) {
auto cl = counter();
FOLLY_ERASE static void mutate(Signed v, CounterRefAndLocal cl) {
auto& c = *cl.counter;
if (cl.local) {
// splitting load/store on the local counter is faster than fetch-and-add
......@@ -153,6 +152,14 @@ class SingletonRelaxedCounter {
}
}
FOLLY_NOINLINE static void mutate_slow(Signed v) { mutate(v, counter()); }
FOLLY_ERASE static void mutate(Signed v, void (&slow)(Signed) = mutate_slow) {
auto const cache = local().cache; // a copy! null before/after LocalLifetime
// fun-ref to trick compiler into emitting a tail call
FOLLY_LIKELY(!!cache) ? mutate(v, {cache, true}) : slow(v);
}
FOLLY_EXPORT FOLLY_ALWAYS_INLINE static CounterAndCache& local() {
// this is a member function local instead of a class member because of
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66944
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment