From: James Sedgwick <jsedgwick@fb.com>
Date: Mon, 4 May 2015 14:23:39 +0000 (-0700)
Subject: explicit instantiation of common Future types
X-Git-Tag: v0.38.0~16
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8e1544536fa676df7e722db0cc9de536c5879998;p=folly.git

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
---

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<void>::getVia(DrivableExecutor* e) {
   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>
 Future<bool> Future<T>::willEqual(Future<T>& f) {
   return collectAll(*this, f).then([](const std::tuple<Try<T>, Try<T>>& 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<T>::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<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
 
 // I haven't included a Future<T&> 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 <folly/futures/detail/ThreadWheelTimekeeper.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 {
 
 Future<void> 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<T>& activate() & {
+  Future<T>& activate() & DEPRECATED {
     core_->activate();
     return *this;
   }
-  Future<T>& deactivate() & {
+  Future<T>& deactivate() & DEPRECATED {
     core_->deactivate();
     return *this;
   }
-  Future<T> activate() && {
+  Future<T> activate() && DEPRECATED {
     core_->activate();
     return std::move(*this);
   }
-  Future<T> deactivate() && {
+  Future<T> 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: