Improve unique_function performance w/small object buffer

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Won't Do
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Server Programmability
    • None
    • None
    • None
    • None
    • None
    • None
    • None

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

            Assignee:
            Unassigned
            Reporter:
            Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: