From 8e1544536fa676df7e722db0cc9de536c5879998 Mon Sep 17 00:00:00 2001 From: James Sedgwick Date: Mon, 4 May 2015 07:23:39 -0700 Subject: [PATCH] explicit instantiation of common Future types Summary: Compiling folly/futures:futures-test, this saves 15% (dbg) and 7% (opt) Compiling all of folly/futures, it's 7% ish for each Main blocker right now is that this generates a spew of deprecated warnings from calls to core_->(de)activate() from Future::(de)activate(). Can the deprecations be moved up to the Future methods instead? Also had to fix willEqual for Future which was borked Test Plan: compiles Reviewed By: hans@fb.com Subscribers: trunkagent, folly-diffs@, jsedgwick, yfeldblum, chalfant FB internal diff: D2021028 Signature: t1:2021028:1430749114:1dd78af47ea91aa5e67929a5884b66ca0c8ae2d8 --- folly/futures/Future-inl.h | 26 +++++++++++++++++++++++++- folly/futures/Future.cpp | 12 ++++++++++++ folly/futures/Future.h | 8 ++++---- folly/futures/detail/Core.h | 14 +++++--------- 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index b3ca83e6..33b758ea 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -1001,11 +1001,27 @@ inline void Future::getVia(DrivableExecutor* e) { waitVia(e).value(); } +namespace detail { + template + struct TryEquals { + static bool equals(const Try& t1, const Try& t2) { + return t1.value() == t2.value(); + } + }; + + template <> + struct TryEquals { + static bool equals(const Try& t1, const Try& t2) { + return true; + } + }; +} + template Future Future::willEqual(Future& f) { return collectAll(*this, f).then([](const std::tuple, Try>& t) { if (std::get<0>(t).hasValue() && std::get<1>(t).hasValue()) { - return std::get<0>(t).value() == std::get<1>(t).value(); + return detail::TryEquals::equals(std::get<0>(t), std::get<1>(t)); } else { return false; } @@ -1059,6 +1075,14 @@ namespace futures { } } +// Instantiate the most common Future types to save compile time +extern template class Future; +extern template class Future; +extern template class Future; +extern template class Future; +extern template class Future; +extern template class Future; + } // namespace folly // I haven't included a Future specialization because I don't forsee us diff --git a/folly/futures/Future.cpp b/folly/futures/Future.cpp index c914ccd3..0f6dc3d1 100644 --- a/folly/futures/Future.cpp +++ b/folly/futures/Future.cpp @@ -17,6 +17,18 @@ #include #include +namespace folly { + +// Instantiate the most common Future types to save compile time +template class Future; +template class Future; +template class Future; +template class Future; +template class Future; +template class Future; + +} + namespace folly { namespace futures { Future sleep(Duration dur, Timekeeper* tk) { diff --git a/folly/futures/Future.h b/folly/futures/Future.h index 924c3805..b26369ce 100644 --- a/folly/futures/Future.h +++ b/folly/futures/Future.h @@ -282,19 +282,19 @@ class Future { /// by then), and it is active (active by default). /// /// Inactive Futures will activate upon destruction. - Future& activate() & { + Future& activate() & DEPRECATED { core_->activate(); return *this; } - Future& deactivate() & { + Future& deactivate() & DEPRECATED { core_->deactivate(); return *this; } - Future activate() && { + Future activate() && DEPRECATED { core_->activate(); return std::move(*this); } - Future deactivate() && { + Future deactivate() && DEPRECATED { core_->deactivate(); return std::move(*this); } diff --git a/folly/futures/detail/Core.h b/folly/futures/detail/Core.h index 85f7b6ca..7e23dd7c 100644 --- a/folly/futures/detail/Core.h +++ b/folly/futures/detail/Core.h @@ -198,7 +198,7 @@ class Core { /// Called by a destructing Future (in the Future thread, by definition) void detachFuture() { - activateNoDeprecatedWarning(); + activate(); detachOne(); } @@ -213,13 +213,14 @@ class Core { } /// May call from any thread - void deactivate() DEPRECATED { + void deactivate() { active_ = false; } /// May call from any thread - void activate() DEPRECATED { - activateNoDeprecatedWarning(); + void activate() { + active_ = true; + maybeCallback(); } /// May call from any thread @@ -258,11 +259,6 @@ class Core { } protected: - void activateNoDeprecatedWarning() { - active_ = true; - maybeCallback(); - } - void maybeCallback() { FSM_START(fsm_) case State::Armed: -- 2.34.1