Commit 7b3f1d1d authored by Hans Fugal's avatar Hans Fugal Committed by dcsommer

(wangle) Use MicroSpinLock

Summary: For great speed

Test Plan:
Before
============================================================================
folly/wangle/test/Benchmark.cpp                 relative  time/iter  iters/s
============================================================================
constantFuture                                             241.19ns    4.15M
promiseAndFuture                                 100.32%   240.42ns    4.16M
withThen                                          44.63%   540.47ns    1.85M
----------------------------------------------------------------------------
oneThen                                                    519.20ns    1.93M
twoThens                                          62.83%   826.41ns    1.21M
fourThens                                         36.80%     1.41us  708.75K
hundredThens                                       1.79%    29.05us   34.42K
----------------------------------------------------------------------------
no_contention                                                4.82ms   207.27
contention                                        62.91%     7.67ms   130.39
============================================================================

After
============================================================================
folly/wangle/test/Benchmark.cpp                 relative  time/iter  iters/s
============================================================================
constantFuture                                             159.79ns    6.26M
promiseAndFuture                                 101.23%   157.84ns    6.34M
withThen                                          41.78%   382.47ns    2.61M
----------------------------------------------------------------------------
oneThen                                                    358.23ns    2.79M
twoThens                                          63.07%   568.00ns    1.76M
fourThens                                         36.89%   971.07ns    1.03M
hundredThens                                       1.76%    20.34us   49.17K
----------------------------------------------------------------------------
no_contention                                                3.75ms   266.75
contention                                        59.83%     6.27ms   159.59
============================================================================

That's a 150% speedup.

Reviewed By: davejwatson@fb.com

Subscribers: net-systems@, fugalh, exa, njormrod

FB internal diff: D1617363

Tasks: 5278220
parent 8ae778e3
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <vector> #include <vector>
#include <folly/Optional.h> #include <folly/Optional.h>
#include <folly/SmallLocks.h>
#include <folly/wangle/Try.h> #include <folly/wangle/Try.h>
#include <folly/wangle/Promise.h> #include <folly/wangle/Promise.h>
...@@ -192,7 +193,7 @@ class Core { ...@@ -192,7 +193,7 @@ class Core {
// this lock isn't meant to protect all accesses to members, only the ones // this lock isn't meant to protect all accesses to members, only the ones
// that need to be threadsafe: the act of setting value_ and callback_, and // that need to be threadsafe: the act of setting value_ and callback_, and
// seeing if they are set and whether we should then continue. // seeing if they are set and whether we should then continue.
std::mutex mutex_; folly::MicroSpinLock mutex_ {0};
}; };
template <typename... Ts> template <typename... Ts>
......
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