Commit 8e154453 authored by James Sedgwick's avatar James Sedgwick Committed by Praveen Kumar Ramakrishnan

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<void> 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
parent 02bb2c34
...@@ -1001,11 +1001,27 @@ inline void Future<void>::getVia(DrivableExecutor* e) { ...@@ -1001,11 +1001,27 @@ inline void Future<void>::getVia(DrivableExecutor* e) {
waitVia(e).value(); waitVia(e).value();
} }
namespace detail {
template <class T>
struct TryEquals {
static bool equals(const Try<T>& t1, const Try<T>& t2) {
return t1.value() == t2.value();
}
};
template <>
struct TryEquals<void> {
static bool equals(const Try<void>& t1, const Try<void>& t2) {
return true;
}
};
}
template <class T> template <class T>
Future<bool> Future<T>::willEqual(Future<T>& f) { Future<bool> Future<T>::willEqual(Future<T>& f) {
return collectAll(*this, f).then([](const std::tuple<Try<T>, Try<T>>& t) { return collectAll(*this, f).then([](const std::tuple<Try<T>, Try<T>>& t) {
if (std::get<0>(t).hasValue() && std::get<1>(t).hasValue()) { 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<T>::equals(std::get<0>(t), std::get<1>(t));
} else { } else {
return false; return false;
} }
...@@ -1059,6 +1075,14 @@ namespace futures { ...@@ -1059,6 +1075,14 @@ namespace futures {
} }
} }
// Instantiate the most common Future types to save compile time
extern template class Future<void>;
extern template class Future<bool>;
extern template class Future<int>;
extern template class Future<int64_t>;
extern template class Future<std::string>;
extern template class Future<double>;
} // namespace folly } // namespace folly
// I haven't included a Future<T&> specialization because I don't forsee us // I haven't included a Future<T&> specialization because I don't forsee us
......
...@@ -17,6 +17,18 @@ ...@@ -17,6 +17,18 @@
#include <folly/futures/detail/ThreadWheelTimekeeper.h> #include <folly/futures/detail/ThreadWheelTimekeeper.h>
#include <folly/Likely.h> #include <folly/Likely.h>
namespace folly {
// Instantiate the most common Future types to save compile time
template class Future<void>;
template class Future<bool>;
template class Future<int>;
template class Future<int64_t>;
template class Future<std::string>;
template class Future<double>;
}
namespace folly { namespace futures { namespace folly { namespace futures {
Future<void> sleep(Duration dur, Timekeeper* tk) { Future<void> sleep(Duration dur, Timekeeper* tk) {
......
...@@ -282,19 +282,19 @@ class Future { ...@@ -282,19 +282,19 @@ class Future {
/// by then), and it is active (active by default). /// by then), and it is active (active by default).
/// ///
/// Inactive Futures will activate upon destruction. /// Inactive Futures will activate upon destruction.
Future<T>& activate() & { Future<T>& activate() & DEPRECATED {
core_->activate(); core_->activate();
return *this; return *this;
} }
Future<T>& deactivate() & { Future<T>& deactivate() & DEPRECATED {
core_->deactivate(); core_->deactivate();
return *this; return *this;
} }
Future<T> activate() && { Future<T> activate() && DEPRECATED {
core_->activate(); core_->activate();
return std::move(*this); return std::move(*this);
} }
Future<T> deactivate() && { Future<T> deactivate() && DEPRECATED {
core_->deactivate(); core_->deactivate();
return std::move(*this); return std::move(*this);
} }
......
...@@ -198,7 +198,7 @@ class Core { ...@@ -198,7 +198,7 @@ class Core {
/// Called by a destructing Future (in the Future thread, by definition) /// Called by a destructing Future (in the Future thread, by definition)
void detachFuture() { void detachFuture() {
activateNoDeprecatedWarning(); activate();
detachOne(); detachOne();
} }
...@@ -213,13 +213,14 @@ class Core { ...@@ -213,13 +213,14 @@ class Core {
} }
/// May call from any thread /// May call from any thread
void deactivate() DEPRECATED { void deactivate() {
active_ = false; active_ = false;
} }
/// May call from any thread /// May call from any thread
void activate() DEPRECATED { void activate() {
activateNoDeprecatedWarning(); active_ = true;
maybeCallback();
} }
/// May call from any thread /// May call from any thread
...@@ -258,11 +259,6 @@ class Core { ...@@ -258,11 +259,6 @@ class Core {
} }
protected: protected:
void activateNoDeprecatedWarning() {
active_ = true;
maybeCallback();
}
void maybeCallback() { void maybeCallback() {
FSM_START(fsm_) FSM_START(fsm_)
case State::Armed: case State::Armed:
......
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