[zeromq-dev] ØMQ VSM data alignment

Ben Kloosterman bklooste at gmail.com
Sat Aug 7 05:13:37 CEST 2010


>> 0x00    void *content;
 >> 0x08    unsigned char flags;
 >> 0x09    unsigned char vsm_size;
 >> 0x0a    unsigned char vsm_data [ZMQ_MAX_VSM_SIZE];
This is incorrect in most cases its 

 0x00    void *content;
 0x08    unsigned char flags;
 0x0a    unsigned char vsm_size;
 0x0d    unsigned char vsm_data [ZMQ_MAX_VSM_SIZE];

Unless you force packing which is not great for performance  ( pack 1 was
probably -3% performance ) 

I posted a code fragment to the list last week which 
- used a union 
- combined flags and size into 1 int field since  it uses 4 bytes anyway  (
you can also use 24 bits for size and remove 4 bytes size from large
messages - max msg size is then 16Meg) 
- set ZMQ_MAX_VSM_SIZE to ensure the total sizeof  was 32 bytes ( which was
28) 
- Put the data at the start so it would be 16 byte aligned
- Set the struct for 16 byte alignment

benchmarked it using VS and got a 2-3% improvement , With Intel I suspect
you will get more as it may use the 8 / 16 byte SSE2 copying which needs 16
byte alignment. If your compiler defaults to pack 1 change it , alignment is
more important. 

Ben

 >-----Original Message-----
 >From: zeromq-dev-bounces at lists.zeromq.org [mailto:zeromq-dev-
 >bounces at lists.zeromq.org] On Behalf Of Pieter Hintjens
 >Sent: Thursday, August 05, 2010 1:09 AM
 >To: 0MQ development list
 >Subject: Re: [zeromq-dev] ØMQ VSM data alignment
 >
 >Matt,
 >
 >I don't think this has been covered.  It would be sensible to have
 >vsm_data aligned but it's something that is IMO worth testing rather
 >than doing on faith.
 >
 >-Pieter




More information about the zeromq-dev mailing list