Skip to content

Commit

Permalink
Protocol: Take advantage of Huffman coding for medium-sized messages
Browse files Browse the repository at this point in the history
Increased the input data size that was allowed for Huffman coding.
  • Loading branch information
skyjake committed Jan 19, 2012
1 parent 907dea1 commit 1e21653
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions doomsday/engine/portable/src/protocol.c
Expand Up @@ -87,6 +87,11 @@
#define MAX_SIZE_MEDIUM 4095 // bytes
#define MAX_SIZE_LARGE PROTOCOL_MAX_DATAGRAM_SIZE

/// Threshold for input data size: messages smaller than this are first compressed
/// with Doomsday's Huffman codes. If the result is smaller than the deflated data,
/// the Huffman coded payload is used (unless it doesn't fit in a medium-sized packet).
#define MAX_HUFFMAN_INPUT_SIZE 4096 // bytes

#define DEFAULT_TRANSMISSION_SIZE 4096

#define TRMF_CONTINUE 0x80
Expand Down Expand Up @@ -307,12 +312,12 @@ void Protocol_Send(void *data, size_t size, nodeid_t destination)

// Let's first see if the encoded contents are under 128 bytes
// as Huffman codes.
if(size <= MAX_SIZE_SMALL*5) // Potentially short enough.
if(size <= MAX_HUFFMAN_INPUT_SIZE) // Potentially short enough.
{
huffData = Huffman_Encode(data, size, &huffSize);
if(huffSize <= MAX_SIZE_SMALL)
{
// We can use this.
// We can use this: set up a small-sized transmission.
transmissionSize = prepareTransmission(huffData, huffSize, false);
}
}
Expand All @@ -339,7 +344,7 @@ void Protocol_Send(void *data, size_t size, nodeid_t destination)
}

// We can choose the smallest compression.
if(huffData && huffSize <= compSize)
if(huffData && huffSize <= compSize && huffSize <= MAX_SIZE_MEDIUM)
{
// Huffman yielded smaller payload.
transmissionSize = prepareTransmission(huffData, huffSize, false);
Expand Down

0 comments on commit 1e21653

Please sign in to comment.