Skip to content

Commit c2c75e8

Browse files
committed
Externalize templates to speed up build
Profiling the mcrouter OSS build with ninjatracing + clang's -ftime-trace indicates that a significant amount of time is spent in repeated template instantiations for ProxyConfig and ServiceInfo (see attached speedscope profile). Add extern template declarations for these classes with their most common parameter (MemcacheRouterInfo) to reduce compile times. On a full build of mcrouter OSS with all tests, this reduces the build time from ~34 minutes to ~29 minutes.
1 parent 60a96f5 commit c2c75e8

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

mcrouter/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ libmcroutercore_a_SOURCES = \
8989
ProxyBase.h \
9090
ProxyConfig-inl.h \
9191
ProxyConfig.h \
92+
ProxyConfig.cpp \
9293
ProxyConfigBuilder.cpp \
9394
ProxyConfigBuilder.h \
9495
ProxyDestination.cpp \

mcrouter/ProxyConfig-inl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "mcrouter/Proxy.h"
1616
#include "mcrouter/lib/config/RouteHandleFactory.h"
1717
#include "mcrouter/lib/fbi/cpp/util.h"
18+
#include "mcrouter/lib/network/gen/MemcacheRouterInfo.h"
1819
#include "mcrouter/routes/McRouteHandleProvider.h"
1920
#include "mcrouter/routes/PrefixSelectorRoute.h"
2021
#include "mcrouter/routes/ProxyRoute.h"
@@ -24,6 +25,8 @@ namespace facebook {
2425
namespace memcache {
2526
namespace mcrouter {
2627

28+
extern template class ProxyConfig<facebook::memcache::MemcacheRouterInfo>;
29+
2730
template <class RouterInfo>
2831
ProxyConfig<RouterInfo>::ProxyConfig(
2932
Proxy<RouterInfo>& proxy,

mcrouter/ProxyConfig.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "mcrouter/ProxyConfig.h"
2+
#include "mcrouter/ServiceInfo.h"
3+
#include "mcrouter/lib/network/gen/MemcacheRouterInfo.h"
4+
5+
namespace facebook::memcache::mcrouter {
6+
template class ProxyConfig<facebook::memcache::MemcacheRouterInfo>;
7+
}

mcrouter/ServiceInfo-inl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
namespace facebook {
4040
namespace memcache {
4141
namespace mcrouter {
42+
43+
extern template class ServiceInfo<facebook::memcache::MemcacheRouterInfo>;
44+
4245
namespace detail {
4346

4447
bool srHostInfoPtrFuncRouteHandlesCommandDispatcher(

mcrouter/ServiceInfo.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
#include "mcrouter/ServiceInfo.h"
99
#include "mcrouter/mcrouter_sr_deps.h"
1010

11-
namespace facebook::memcache::mcrouter::detail {
11+
namespace facebook::memcache::mcrouter {
1212

13+
template class ServiceInfo<facebook::memcache::MemcacheRouterInfo>;
14+
15+
namespace detail {
1316
bool srHostInfoPtrFuncRouteHandlesCommandDispatcher(
14-
const HostInfoPtr& host,
15-
std::string& tree,
16-
const int level) {
17+
const HostInfoPtr& host, std::string& tree, const int level) {
1718
bool haveHost = (host != nullptr);
1819
tree.append(
1920
std::string(level, ' ') +
@@ -23,5 +24,5 @@ bool srHostInfoPtrFuncRouteHandlesCommandDispatcher(
2324
'\n');
2425
return false;
2526
}
26-
27-
} // namespace facebook::memcache::mcrouter::detail
27+
} // namespace detail
28+
} // namespace facebook::memcache::mcrouter

0 commit comments

Comments
 (0)