todb/packetfu — pull request #11 by justfalter (2012-07-29 03:06:38+00:00)
Title: Some more performance improvements

Hi there,

I got inspired today, and put together some more performance improvements.

1. I broke out many of the components (EthHeader, TCPHeader, etc) into their own files. This was simply to make it easier for me to read things.

2. I reduced (possibly removed) reliance upon PacketFu::Packet#method_missing? by creating mixins that enable access to *Header methods. method_missing? is hella-slow.

3. Probably the biggest gain: I removed redundant calls to @ip_header.read(..), @tcp_header.read(..), etc in *Packet.read() methods. These were already being called from within *Header.read() when 'self[:body].read(...)' was being called.

4. Changed all instances of 'str.force_encoding "binary"' to 'str.force_encoding Encoding::BINARY' ... The former would result in extra string/hash lookups within the encoding library.

The net result is as follows:
Parsing TCP Packets:
Packet.parse() is now ~2 times faster.