-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
-
Service Arch
Our unique_function class template always allocates. Its 'Impl` is held by unique_ptr. We could probably benefit from a union of inline storage if the callable is small enough to fit within an aligned buffer of a few pointers' size.
https://llvm.org/doxygen/FunctionExtras_8h_source.html#l00081
If the callable size is less than 3 pointers, then there's no allocation. It's just moved into the unique_function object.
I think this optimization could be a win in async and Future dispatch costs if we bind a reasonable amount of stuff to the relevant lambdas.
Abseil is calling this absl::AnyInvocable but they use a max inline storage of 2 pointers instead of 3. https://github.com/abseil/abseil-cpp/blob/master/absl/functional/internal/any_invocable.h#L93. Their naming is standards-influenced
Or we could switch our home-grown `unique_function` out to use a vendored implementation instead (like one of those above).