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

use monotonic_buffer_resource to reduce allocations in MetricTree merging algorithm

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Server Programmability

      As part of PM-1812 and tcmalloc evaluation, we've identified allocator "hot spots" in particular those where allocations are short-lived and freed at the end of a block scope in an RAII-compatible way. C++17 provides the std::monotonic_buffer_resource which seems perfect for those cases.

      we can switch to std::pmr::vector and std::pmr::string inside the functions. We can probably make up a pmr-based BSONObjBuilder as well.
      The standard containers do this cool trick of propagating their allocators to their elements. This is a reason to use emplace_back instead of push_back, because emplace_back can sneakily provide the extra allocator argument to the element being constructed. So you can have a vector of vector of vector of strings and all objects would share the allocator that was given to the toplevel object.
      https://quuxplusone.github.io/blog/2023/06/02/not-so-quick-pmr/#allocator-extended-constructors
      https://www.cppstd17.com/code/pmr/pmr2.cpp.html

      The real power here is from not bothering with global new and delete for all the interior elements.

      so the monotonic buffer resource ends up owning a very small sequence of geometrically increasing memory buffers. So you have to visit new and delete only a few times, regardless of how many internal allocations the memory resource made.

            Assignee:
            Unassigned Unassigned
            Reporter:
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: