Reduce allocations in lzma_encoder
Every time we flushed, we were freeing the buffer and then re-allocating
it. The usage pattern has a very constant memory usage and no peaks, so
a free list will reduce fragmentation and prevent us from thrashing the
allocator.
Change-Id: I82060dff1fe95c950e39b1bef0955e20abc5b99a
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/events/logging/lzma_encoder.h b/aos/events/logging/lzma_encoder.h
index b4964fb..3136d93 100644
--- a/aos/events/logging/lzma_encoder.h
+++ b/aos/events/logging/lzma_encoder.h
@@ -54,6 +54,11 @@
lzma_stream stream_;
uint32_t compression_preset_;
std::vector<ResizeableBuffer> queue_;
+ // Since we pretty much just allocate a couple of buffers, then allocate and
+ // release them over and over with very similar memory usage and without much
+ // variation in the peak usage, put the allocate chunks in a free queue to
+ // reduce fragmentation.
+ std::vector<ResizeableBuffer> free_queue_;
bool finished_ = false;
// Total bytes that resulted from encoding raw data since the last call to
// Reset.