-
Notifications
You must be signed in to change notification settings - Fork 706
Small size optimization & custom deallocator for rerun::Collection #4256
Description
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)