Optimize, fix memory zeroing and refactor BinaryQueue
BinaryQueue is a class responsible for buffering data received from
sockets before deserialization, vendored from DPL. It stores the
received data as a list of blocks, which is probably the optimal
approach given the constraints of the services framework here. However,
its implementation is a little inefficient and incorrect:
- Stores data in std::vector<unsigned char> instead of RawBuffer.
Because of that, any piece of data that passes through a socket may
live in memory much longer than it should.
- Erases elements from the front of a std::vector. This means all the
other elements need to be shifted, which could even result in
quadratic complexity given large enough socket reads and small enough
messages.
- Always copies incoming data. This means all of incoming traffic has to
be copied one more time than it needs to.
I have fixed the first issue in the obvious way. To fix the second
issue, I have added a new member that tracks how many bytes have been
read from the first bucket in the queue, which makes physically erasing
elements from the vector unnecessary. Lastly, I changed the push
signature from taking a pointer and a size to taking a RawBuffer&&,
which eliminated some copies and made the remaining ones more explicit.
Change-Id: I36932d5492815e38bf1cdab249327d26c9805ac6
13 files changed: