Commit 249e3805 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by JoelMarcey

get_fast/get_weak_fast API for folly::Singleton

Summary: This adds API which makes folly::Singleton as performant as Meyers/static-object singletons.

Test Plan:
unit test + benchmark

============================================================================
folly/experimental/test/SingletonTest.cpp       relative  time/iter  iters/s
============================================================================
NormalSingleton                                            333.32ps    3.00G
MeyersSingleton                                  100.00%   333.33ps    3.00G
FollySingletonSlow                                 0.35%    94.36ns   10.60M
FollySingletonFast                                99.43%   335.24ps    2.98G
FollySingletonFastWeak                             0.62%    53.74ns   18.61M
============================================================================

Reviewed By: alikhtarov@fb.com

Subscribers: trunkagent, folly-diffs@

FB internal diff: D1741961

Signature: t1:1741961:1418765462:d9806f1bf5275bfbe2c4c53a41b735bda93753fe
parent adc966e1
......@@ -63,7 +63,7 @@ void SingletonVault::destroyInstance(SingletonMap::iterator entry_it) {
<< "is " << entry.instance.get() << " with use_count of "
<< entry.instance.use_count();
}
entry.state = SingletonEntryState::Dead;
entry.state = detail::SingletonEntryState::Dead;
entry.instance.reset();
}
......
This diff is collapsed.
......@@ -425,7 +425,7 @@ BENCHMARK_RELATIVE(MeyersSingleton, n) {
}
}
BENCHMARK_RELATIVE(FollySingleton, n) {
BENCHMARK_RELATIVE(FollySingletonSlow, n) {
SingletonVault benchmark_vault;
Singleton<BenchmarkSingleton> benchmark_singleton(
nullptr, nullptr, &benchmark_vault);
......@@ -436,6 +436,28 @@ BENCHMARK_RELATIVE(FollySingleton, n) {
}
}
BENCHMARK_RELATIVE(FollySingletonFast, n) {
SingletonVault benchmark_vault;
Singleton<BenchmarkSingleton> benchmark_singleton(
nullptr, nullptr, &benchmark_vault);
benchmark_vault.registrationComplete();
for (size_t i = 0; i < n; ++i) {
doNotOptimizeAway(benchmark_singleton.get_fast());
}
}
BENCHMARK_RELATIVE(FollySingletonFastWeak, n) {
SingletonVault benchmark_vault;
Singleton<BenchmarkSingleton> benchmark_singleton(
nullptr, nullptr, &benchmark_vault);
benchmark_vault.registrationComplete();
for (size_t i = 0; i < n; ++i) {
benchmark_singleton.get_weak_fast();
}
}
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
google::InitGoogleLogging(argv[0]);
......
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