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

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Service Arch
    • Service Arch 2024-04-29, Service Arch 2024-05-13

      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:
            billy.donahue@mongodb.com Billy Donahue
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: