Skip to content

Commit

Permalink
Externalize templates to speed up build
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mszabo-wikia committed Dec 19, 2024
1 parent 60a96f5 commit c2c75e8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions mcrouter/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ libmcroutercore_a_SOURCES = \
ProxyBase.h \
ProxyConfig-inl.h \
ProxyConfig.h \
ProxyConfig.cpp \
ProxyConfigBuilder.cpp \
ProxyConfigBuilder.h \
ProxyDestination.cpp \
Expand Down
3 changes: 3 additions & 0 deletions mcrouter/ProxyConfig-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "mcrouter/Proxy.h"
#include "mcrouter/lib/config/RouteHandleFactory.h"
#include "mcrouter/lib/fbi/cpp/util.h"
#include "mcrouter/lib/network/gen/MemcacheRouterInfo.h"
#include "mcrouter/routes/McRouteHandleProvider.h"
#include "mcrouter/routes/PrefixSelectorRoute.h"
#include "mcrouter/routes/ProxyRoute.h"
Expand All @@ -24,6 +25,8 @@ namespace facebook {
namespace memcache {
namespace mcrouter {

extern template class ProxyConfig<facebook::memcache::MemcacheRouterInfo>;

template <class RouterInfo>
ProxyConfig<RouterInfo>::ProxyConfig(
Proxy<RouterInfo>& proxy,
Expand Down
7 changes: 7 additions & 0 deletions mcrouter/ProxyConfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "mcrouter/ProxyConfig.h"
#include "mcrouter/ServiceInfo.h"
#include "mcrouter/lib/network/gen/MemcacheRouterInfo.h"

namespace facebook::memcache::mcrouter {
template class ProxyConfig<facebook::memcache::MemcacheRouterInfo>;
}
3 changes: 3 additions & 0 deletions mcrouter/ServiceInfo-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
namespace facebook {
namespace memcache {
namespace mcrouter {

extern template class ServiceInfo<facebook::memcache::MemcacheRouterInfo>;

namespace detail {

bool srHostInfoPtrFuncRouteHandlesCommandDispatcher(
Expand Down
13 changes: 7 additions & 6 deletions mcrouter/ServiceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#include "mcrouter/ServiceInfo.h"
#include "mcrouter/mcrouter_sr_deps.h"

namespace facebook::memcache::mcrouter::detail {
namespace facebook::memcache::mcrouter {

template class ServiceInfo<facebook::memcache::MemcacheRouterInfo>;

namespace detail {
bool srHostInfoPtrFuncRouteHandlesCommandDispatcher(
const HostInfoPtr& host,
std::string& tree,
const int level) {
const HostInfoPtr& host, std::string& tree, const int level) {
bool haveHost = (host != nullptr);
tree.append(
std::string(level, ' ') +
Expand All @@ -23,5 +24,5 @@ bool srHostInfoPtrFuncRouteHandlesCommandDispatcher(
'\n');
return false;
}

} // namespace facebook::memcache::mcrouter::detail
} // namespace detail
} // namespace facebook::memcache::mcrouter

0 comments on commit c2c75e8

Please sign in to comment.