One tiny thought after a moment's glance: your queue can allocate on every item: `queue = queue[1:]` is convenient but discards the capacity at the first element. We should probably have a slice-backed ring buffer in the stdlib actually. container/ring.Buffer seems like a possibility.
That said, if we want to solve that issue I'd rather use a linked list with potentially a pool for elements. The Ring API is a pain to deal with if you need to grow and it doesn't shrink 😅
and FWIW I suspect the resulting performance increase might not be _that_ negligible: it can result in O(n) allocations for n items passing through the channel.
Comments
i'm happy that this led to you writing a new article on your site 😁
I thought about this but I didn't want to overcomplicate the code for a small performance increase.
Then your code might look like this: https://gist.github.com/rogpeppe/ce9945c8bd696c59e5d208bbe717648e
Thanks Rog, always nice to be sniped by you :P