From 1f656e7d6b879973b743442287f8620e87e34d2a Mon Sep 17 00:00:00 2001 From: Anton Likhtarov Date: Mon, 18 May 2015 16:13:09 -0700 Subject: [PATCH] Some optimizations 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::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::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 | 7 +------ folly/experimental/fibers/Fiber.h | 12 +++++++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/folly/experimental/fibers/Fiber-inl.h b/folly/experimental/fibers/Fiber-inl.h index 9ba00115..1d4b5e32 100644 --- a/folly/experimental/fibers/Fiber-inl.h +++ b/folly/experimental/fibers/Fiber-inl.h @@ -40,12 +40,7 @@ inline void* Fiber::getUserBuffer() { } template -T& Fiber::LocalData::get() { - if (data_) { - assert(*dataType_ == typeid(T)); - return *reinterpret_cast(data_); - } - +T& Fiber::LocalData::getSlow() { dataSize_ = sizeof(T); dataType_ = &typeid(T); if (sizeof(T) <= kBufferSize) { diff --git a/folly/experimental/fibers/Fiber.h b/folly/experimental/fibers/Fiber.h index 5dbb4878..c4dbec00 100644 --- a/folly/experimental/fibers/Fiber.h +++ b/folly/experimental/fibers/Fiber.h @@ -24,6 +24,7 @@ #include #include #include +#include namespace folly { namespace fibers { @@ -125,11 +126,20 @@ class Fiber { LocalData& operator=(const LocalData& other); template - T& get(); + T& get() { + if (data_) { + assert(*dataType_ == typeid(T)); + return *reinterpret_cast(data_); + } + return getSlow(); + } void reset(); //private: + template + FOLLY_NOINLINE T& getSlow(); + static void* allocateHeapBuffer(size_t size); static void freeHeapBuffer(void* buffer); -- 2.34.1