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

Used sized_free (or similar) rather than free everywhere we know the allocation size

    • Service Arch
    • Fully Compatible
    • v8.0
    • Service Arch 2024-04-29, Workload Scheduling 2024-05-27, Workload Scheduling 2024-06-10

      This saves a bit of work for the allocator at free time. I don't expect this to be a huge win but we might be able to save a small amount of CPU by doing this in a few key places:

      • SharedBuffer (covers at least BSONObj and Message)
      • StackAllocator (Used by StackBufBuilder when exceeding inline size)

      There are a few places in query code that would benefit from this as well

      • DocumentStorage::_cache (search for unique_ptr<char[]> in document.cpp)
      • A handful of places in SBE use std::free or delete[]

      Note that sized_free is a C23 addition and while supported by the new tcmalloc may not be available everywhere. We should consider using switching things using mongoMalloc to ::operator new(size) and ::operator delete(ptr, size) instead. Another advantage to this is that tcmalloc uses (slightly) more efficient rules for ::operator new than for malloc.

            Assignee:
            ryan.berryhill@mongodb.com Ryan Berryhill
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: