Reduce number of allocations for events/messages/queries/caps and structures in general
(Originally in #291 (closed))
status
- structurefields are inlined in
GstStructure
: !392 (merged) -
GstValueList
andGstValueArray
have been inlined : !402 (merged)
overview
Right now for events, messages and queries we have the following:
- One allocation for
GstEvent
(orGstMessage
orGstQuery
) - One allocation for
GstStructure
- One allocation for
GArray
- Allocations for the contents of that array :
GQuark
+GValue
Ideally we should fold those altogether (like GstBufferList
does) by inlining as much as possible in the top-level structure. Something like this :
typedef struct {
GstMessage message;
GstStructureImpl structure; /* Note: not a pointer */
} GstMessageImpl;
struct _GstStructureField /* Same as existing */
{
GQuark name;
GValue value;
};
typedef struct {
GstStructure s;
gint *parent_refcount;
guint fields_len;
guint fields_alloc;
GstStructureField *fields;
GstStructureField arr[1]; /* self-allocated, expands at the end */
} GstStructureImpl;
The above could improve:
- Locality of data
- Less micro-allocations (with the overhead of whatever slice/tcmalloc/whatever allocator you're using)
Note : Unfortunately GArray
can't be initialized statically (i.e. you provide the pointer instead of glib allocating it). We also don't need some features (zero-terminated, destroynotify, ...) of it. So we could implemented our own GstStructureArray
internal variant which would allow us to inline even more.
Note : This would also require modifying slightly how queries/events/messages are currently created. You'd have to first figure out the ideal number of fields to be allocated (including number of answer fields for queries and padding for some external users) and then fill in the structure.