zeromq/libzmq — pull request #630 by ulikoehler (2013-08-18 21:56:28+00:00)
Title: Optimized zmq::msg_t for constant messages

Currently, constant messages are LMSG-types. LMSG initialization causes two mallocs:
* A *content_t* instance that saves the parameters
* An *atomic_counter_t* for refcounting

When allocating a large numbers of messages with a NULL *ffn* argument to *zmq_msg_init_data*, this behaviour could cause memory fragmentation. It will cause poor performance.

This patch adds the new message type CMSG ("Constant"), which saves the data pointer and the data size inline. A message is set to cmsg-type if the *ffn* arg is NULL.

In a quick benchmark repeatedly init_data'ing and closing the same message with constant data, the performance gained by using cmsgs is +320% !
I think that's worth the minor extra complexity (the user API is not changed at all, existing applications will profit from this patch without recompilation).