Optimized message decoding #7

Merged
merged 1 commit into from Jun 6, 2012

Conversation

Projects
None yet
2 participants
Contributor

iconara commented May 7, 2012

This patch roughly halves the time spent decoding messages. Instead of doing three #unpack calls it does just one, and the format string is now a constant.

Obviously this doesn't double the consumer performance, there's a lot of other overhead in just moving the bits around, but it's something.

There's a lot of string literals that could be moved into constants in the rest of the code, I think there's a potential for getting at least a 10% speed increase in just fixing that. Code that runs thousands of times per second should not use literal strings, they create way too much garbage (remember that in Ruby a literal string always creates a new object since strings are mutable -- this is a huge performance hog, especially in MRI). If you want I can send a patch for that too.

Optimized message decoding
One #unpack call, with a constant format specifier, yields about 50% speedup in message decoding.
Contributor

iconara commented May 7, 2012

Btw. the first unpack call had a #to_i, which I didn't see the use for (it should always be an int -- and the third call, that uses the same format [N], did not have it). Do you know if there was a reason for it?

acrosa added a commit that referenced this pull request Jun 6, 2012

@acrosa acrosa merged commit f74d483 into acrosa:master Jun 6, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment