Commit 5022d546 authored by Eric Niebler's avatar Eric Niebler Committed by Facebook Github Bot 2

Reimplement folly::Function to improve compile times.

Summary:
folly::Function is causing significant compile time regressions. Reimplement it in a simpler way.

These are the times for a file containing 1000 instantiations of folly::Fuction (old), folly::Function (new), and std::function with **g++ 4.8 -O3** on my CentOS7 server.

|        | Old `folly::Function` | `std::function` | New `folly::Function` |
|--------|-----------------------|-----------------|-----------------------|
| Time   | 10m37s                | 0m16.81s        | 0m14.75s              |

And for the executable size:

|        | Old `folly::Function` | `std::function` | New `folly::Function` |
|--------|-----------------------|-----------------|-----------------------|
| Size   | 10,409,504            | 732,150         | 562,781               |

That's a **43X** improvement in compile times and an **18X** reduction in executable bloat over the old implementation.

The times for **clang (trunk)** are very different:

|       | Old `folly::Function` | `std::function` | New `folly::Function` |
|-------|-----------------------|-----------------|-----------------------|
| Time  | 4m6s                  | 0m45.27s        | 0m11.78s              |

That's a **20X** improvement over the old implementation and almost a **4X** improvement over `std::function`.

For **gcc-5.3.0**, compile times are again different:

|       | Old `folly::Function` | `std::function` | New `folly::Function` |
|-------|-----------------------|-----------------|-----------------------|
| Time  | 2m49s                 | 0m18.99s        | 0m20.70s              |

With gcc-5.3, the new implementation "only" compiles 8x faster than the old one, and is roughly the same as `std::function`.

Reviewed By: spacedentist, ot, luciang

Differential Revision: D3199985

fb-gh-sync-id: b97982a9dc3a63140510babea34988932e89f2d9
fbshipit-source-id: b97982a9dc3a63140510babea34988932e89f2d9
parent 9383e1ca
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -341,8 +341,6 @@ nobase_follyinclude_HEADERS = \
Traits.h \
Unicode.h \
Function.h \
Function-inl.h \
Function-pre.h \
Uri.h \
Uri-inl.h \
Varint.h \
......
......@@ -374,11 +374,7 @@ class Core {
// sizeof(Core<T>) == size(Core<U>).
// See Core::convert for details.
folly::Function<
void(Try<T>&&),
folly::FunctionMoveCtor::MAY_THROW,
8 * sizeof(void*)>
callback_;
folly::Function<void(Try<T>&&)> callback_;
// place result_ next to increase the likelihood that the value will be
// contained entirely in one cache line
folly::Optional<Try<T>> result_;
......
This diff is collapsed.
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