Commit 6ed9d378 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

shrink UniqueInstance ctor

Summary:
It is monomorphized but called rarely. Best to optimize for size.

The `UniqueInstance` ctor is currently called in the constructor of each translation unit for each distinct instance of `SingletonThreadLocal`.

`UniqueInstance` may be extended to more use-cases so it is worthwhile optimizing for size.

Reviewed By: luciang

Differential Revision: D27602938

fbshipit-source-id: e4077830544516219485814ccc48805b7bb38e34
parent ebe2f775
...@@ -83,13 +83,9 @@ std::string render(Value value) { ...@@ -83,13 +83,9 @@ std::string render(Value value) {
} // namespace } // namespace
void UniqueInstance::enforce( void UniqueInstance::enforce(Arg& arg) noexcept {
Ptr tmpl, auto const& local = arg.local;
Ptr const* ptrs, auto& global = StaticSingletonManager::create<Value>(arg.global);
std::uint32_t key_size,
std::uint32_t mapped_size,
Value& global) noexcept {
Value const local{tmpl, ptrs, key_size, mapped_size};
if (!global.tmpl) { if (!global.tmpl) {
global = local; global = local;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <cstdint> #include <cstdint>
#include <typeinfo> #include <typeinfo>
#include <folly/CppAttributes.h>
#include <folly/detail/StaticSingletonManager.h> #include <folly/detail/StaticSingletonManager.h>
namespace folly { namespace folly {
...@@ -30,12 +31,14 @@ class UniqueInstance { ...@@ -30,12 +31,14 @@ class UniqueInstance {
explicit UniqueInstance(...) noexcept {} explicit UniqueInstance(...) noexcept {}
#else #else
template <template <typename...> class Z, typename... Key, typename... Mapped> template <template <typename...> class Z, typename... Key, typename... Mapped>
FOLLY_EXPORT explicit UniqueInstance( FOLLY_EXPORT FOLLY_ALWAYS_INLINE explicit UniqueInstance(
tag_t<Z<Key..., Mapped...>>, tag_t<Key...>, tag_t<Mapped...>) noexcept { tag_t<Z<Key..., Mapped...>>, tag_t<Key...>, tag_t<Mapped...>) noexcept {
Ptr const tmpl = &typeid(key_t<Z>); static Ptr const tmpl = &typeid(key_t<Z>);
static Ptr const ptrs[] = {&typeid(Key)..., &typeid(Mapped)...}; static Ptr const ptrs[] = {&typeid(Key)..., &typeid(Mapped)...};
auto& global = createGlobal<Value, key_t<Z, Key...>>(); static Arg arg{
enforce(tmpl, ptrs, sizeof...(Key), sizeof...(Mapped), global); {tmpl, ptrs, sizeof...(Key), sizeof...(Mapped)},
{tag<Value, key_t<Z, Key...>>}};
enforce(arg);
} }
#endif #endif
...@@ -59,15 +62,12 @@ class UniqueInstance { ...@@ -59,15 +62,12 @@ class UniqueInstance {
std::uint32_t key_size; std::uint32_t key_size;
std::uint32_t mapped_size; std::uint32_t mapped_size;
}; };
struct Arg {
Value local;
StaticSingletonManager::ArgCreate<true> global;
};
// Under Clang, this call signature shrinks the aligned and padded size of static void enforce(Arg& arg) noexcept;
// call-sites, as compared to a call signature taking Value or Value const&.
static void enforce(
Ptr tmpl,
Ptr const* ptrs,
std::uint32_t key_size,
std::uint32_t mapped_size,
Value& global) noexcept;
}; };
} // namespace detail } // namespace detail
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment