Some optimizations
authorAnton Likhtarov <alikhtarov@fb.com>
Mon, 18 May 2015 23:13:09 +0000 (16:13 -0700)
committerwoo <woo@fb.com>
Tue, 26 May 2015 18:32:15 +0000 (11:32 -0700)
Summary:
1. Eliminate some string -> StringPiece -> strings conversions
2. Mcrouter: eliminated unnecessary inlining by moving slow path logic into its own method.

Using a test setup with shadow sampling enabled and shadowing some requests,
(typical prod setup), this brings down the cost from ~1.4% cpu in standalone mcrouter to ~0.2%:

```
before:

+ 0.70%          3898  mcrouter_orig  mcrouter_orig  [.] FbAdditionalProxyRequestLogger::logReply
+ 0.13%           864  mcrouter_orig  mcrouter_orig  [.] EventGroup<ScubaRow>::processExtraSamplers
+ 0.58%          3347  mcrouter_orig  mcrouter_orig  [.] DynamicScubaSampler::getSampler

~ 1.41% total

after:

+ 0.18%          1223  mcrouter_fix  mcrouter_fix  [.] FbAdditionalProxyRequestLogger::logReply
+ 0.04%           205  mcrouter_fix  mcrouter_fix  [.] EventGroup<ScubaRow>::processSampler

~ 0.22% total
```

Fiber local optimization might have more of an effect.

Test Plan:
unit tests

Reviewed By: pavlo@fb.com

Subscribers: trunkagent, fbcode-common-diffs@, alikhtarov, folly-diffs@, yfeldblum, darshan, chalfant

FB internal diff: D2089133

Tasks: 5414865

Signature: t1:2089133:1432338487:4158dc6b720c04f43820193e73b98d4197afcffa

folly/experimental/fibers/Fiber-inl.h
folly/experimental/fibers/Fiber.h

index 9ba00115335c49cb2a6b2f51f1bac0d46e2046b9..1d4b5e3290c45cf8e1fad69ca154e46b3c4bb0ca 100644 (file)
@@ -40,12 +40,7 @@ inline void* Fiber::getUserBuffer() {
 }
 
 template <typename T>
-T& Fiber::LocalData::get() {
-  if (data_) {
-    assert(*dataType_ == typeid(T));
-    return *reinterpret_cast<T*>(data_);
-  }
-
+T& Fiber::LocalData::getSlow() {
   dataSize_ = sizeof(T);
   dataType_ = &typeid(T);
   if (sizeof(T) <= kBufferSize) {
index 5dbb48785bf665b3ec8b7379b875fd0f9cc8cac7..c4dbec0045e518e16cfe1cc775584938dc3e20b0 100644 (file)
@@ -24,6 +24,7 @@
 #include <folly/CPortability.h>
 #include <folly/IntrusiveList.h>
 #include <folly/experimental/fibers/BoostContextCompatibility.h>
+#include <folly/Portability.h>
 
 namespace folly { namespace fibers {
 
@@ -125,11 +126,20 @@ class Fiber {
     LocalData& operator=(const LocalData& other);
 
     template <typename T>
-    T& get();
+    T& get() {
+      if (data_) {
+        assert(*dataType_ == typeid(T));
+        return *reinterpret_cast<T*>(data_);
+      }
+      return getSlow<T>();
+    }
 
     void reset();
 
     //private:
+    template <typename T>
+    FOLLY_NOINLINE T& getSlow();
+
     static void* allocateHeapBuffer(size_t size);
     static void freeHeapBuffer(void* buffer);