From b28df748c38bc5feca7fa2076b59940c9c1c95b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Szab=C3=B3?= Date: Thu, 19 Dec 2024 13:17:14 +0100 Subject: [PATCH] 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. --- mcrouter/Makefile.am | 1 + mcrouter/ProxyConfig-inl.h | 3 +++ mcrouter/ProxyConfig.cpp | 7 +++++++ mcrouter/ServiceInfo-inl.h | 3 +++ mcrouter/ServiceInfo.cpp | 9 ++++++--- 5 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 mcrouter/ProxyConfig.cpp diff --git a/mcrouter/Makefile.am b/mcrouter/Makefile.am index d2089cd54..8be8af9c3 100644 --- a/mcrouter/Makefile.am +++ b/mcrouter/Makefile.am @@ -89,6 +89,7 @@ libmcroutercore_a_SOURCES = \ ProxyBase.h \ ProxyConfig-inl.h \ ProxyConfig.h \ + ProxyConfig.cpp \ ProxyConfigBuilder.cpp \ ProxyConfigBuilder.h \ ProxyDestination.cpp \ diff --git a/mcrouter/ProxyConfig-inl.h b/mcrouter/ProxyConfig-inl.h index 393ec7ffa..9cdd404fc 100644 --- a/mcrouter/ProxyConfig-inl.h +++ b/mcrouter/ProxyConfig-inl.h @@ -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" @@ -24,6 +25,8 @@ namespace facebook { namespace memcache { namespace mcrouter { +extern template class ProxyConfig; + template ProxyConfig::ProxyConfig( Proxy& proxy, diff --git a/mcrouter/ProxyConfig.cpp b/mcrouter/ProxyConfig.cpp new file mode 100644 index 000000000..b8d25d51e --- /dev/null +++ b/mcrouter/ProxyConfig.cpp @@ -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; +} diff --git a/mcrouter/ServiceInfo-inl.h b/mcrouter/ServiceInfo-inl.h index 48e04cb93..41744e574 100644 --- a/mcrouter/ServiceInfo-inl.h +++ b/mcrouter/ServiceInfo-inl.h @@ -39,6 +39,9 @@ namespace facebook { namespace memcache { namespace mcrouter { + +extern template class ServiceInfo; + namespace detail { bool srHostInfoPtrFuncRouteHandlesCommandDispatcher( diff --git a/mcrouter/ServiceInfo.cpp b/mcrouter/ServiceInfo.cpp index aa71f1598..a01bd9f0b 100644 --- a/mcrouter/ServiceInfo.cpp +++ b/mcrouter/ServiceInfo.cpp @@ -8,8 +8,11 @@ #include "mcrouter/ServiceInfo.h" #include "mcrouter/mcrouter_sr_deps.h" -namespace facebook::memcache::mcrouter::detail { +namespace facebook::memcache::mcrouter { +template class ServiceInfo; + +namespace detail { bool srHostInfoPtrFuncRouteHandlesCommandDispatcher( const HostInfoPtr& host, std::string& tree, @@ -23,5 +26,5 @@ bool srHostInfoPtrFuncRouteHandlesCommandDispatcher( '\n'); return false; } - -} // namespace facebook::memcache::mcrouter::detail +} // namespace detail +} // namespace facebook::memcache::mcrouter