Skip to content

Small size optimization & custom deallocator for rerun::Collection #4256

@Wumpf

Description

@Wumpf

Whenever a rerun::Collection is owning the data via an allocation, it currently stores it in a std::vector using the default allocator
It would be nice to instead be able to specify arbitrary deallocation for any pointer that is owned by rerun::Collection. Also since rerun::Collection is immutable we shouldn't pay for the capacity field of std::vector either, bloating the size of rerun::Collection unecessarily

Proposed internal data struct to that end:

TElement* _data;
void (*_dealloc)(TElement*);
size_t _size;

Whenever the data is borrowed, _dealloc is null.

Note that this model is also relatively friendly to a small-buffer/inline-buffer optimization:
We can sacrifice one bit on _size to indicate whether an inline buffer is used and then use _data + _dealloc as storage for the inline buffer.

A working prototype of a different implementation of an inline buffer can be found on this branch https://github.com/rerun-io/rerun/tree/andreas/cpp/rerun-collections-small-collection-optimization
(has no custom deallocator support)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestsdk-cppC/C++ API specific

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions