From 9d9ba1a442485c1b77de45c04162a88039ff6d1f Mon Sep 17 00:00:00 2001 From: Michael Abbott Date: Wed, 11 Aug 2010 16:42:44 -0500 Subject: [PATCH] Add CA message header size optimisation. If a packet is sufficiently small it can be worth the small optimisation of saving the 8 bytes in a large packet header. --- src/rsrv/caserverio.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/rsrv/caserverio.c b/src/rsrv/caserverio.c index a073f4283..a01d4fe3c 100644 --- a/src/rsrv/caserverio.c +++ b/src/rsrv/caserverio.c @@ -33,6 +33,10 @@ #define epicsExportSharedSymbols #include "server.h" +/* As an optimisation, any message allocated with a large header is resized to + * use a small header if the payload size is below this threshold. */ +#define SMALL_MESSAGE_THRESHOLD 65 + /* * cas_send_bs_msg() * @@ -350,8 +354,19 @@ void cas_commit_msg ( struct client *pClient, ca_uint32_t size ) if ( pMsg->m_postsize == htons ( 0xffff ) ) { ca_uint32_t * pLW = ( ca_uint32_t * ) ( pMsg + 1 ); assert ( size <= ntohl ( *pLW ) ); - pLW[0] = htonl ( size ); - size += sizeof ( caHdr ) + 2 * sizeof ( *pLW ); + if (size < SMALL_MESSAGE_THRESHOLD) { + /* If the message is sufficiently small it can be worth converting a + * large message header into a small header. This saves us all of 8 + * bytes over the wire, so it's not such a big deal. */ + pMsg->m_postsize = htons((ca_uint16_t) size); + pMsg->m_count = htons((ca_uint16_t) ntohl(pLW[1])); + memmove(pLW, pLW + 2, size); + size += sizeof(caHdr); + } + else { + pLW[0] = htonl ( size ); + size += sizeof ( caHdr ) + 2 * sizeof ( *pLW ); + } } else { assert ( size <= ntohs ( pMsg->m_postsize ) );