Description
The ruby binary decoder has some inefficient memory usage patterns. The decoding process relies on `unpack` quite heavily, but it allocates an array that is not used as we just access the first element of the result. In ruby 2.4 we can use the optimized version of this, `unpack1` which avoids allocating the unused array. In `byte!`, we can go one step further and just use the `readbyte` method provided by the IO module - this improves the performance of `byte!` by about 50%. Additionally, there are a few strings in the encoder and decoder that should be frozen to reduce unnecessary string allocations.
With these changes, I've seen about a 20% performance improvement when decoding.
Attachments
Issue Links
- links to