Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-69381

Improve unique_function performance w/small object buffer

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 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).

            Assignee:
            backlog-server-servicearch [DO NOT USE] Backlog - Service Architecture
            Reporter:
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: