Closed fhunleth closed 3 years ago
As a side note, we've been using this on Nerves with RingLogger for a really long time. I've been meaning to contribute back, but never got to it (super sorry about that). I have a couple minor follow-up PRs based on how this one turns out.
This switches the implementation from using the general purpose
:queue
module to enable optimizations for the circular buffer use case. At a high level, an Okasaki queue is still used. Since insertion to a circular buffer always requires a removal once the buffer reaches its max size, this change makes it possible to do this in one step. Previously, this was a call to:queue
to remove one element and then a call to insert the new one.With the general caveat on microbenchmarks, the new implementation is a small performance improvement and reduces the garbage created when managing the structure. The following results are from inserting items repeatedly into a CircularBuffer. "cb2" is the new implementation and "cb" is the
:queue
implementation in the results below.