smol-rs / async-broadcast

Async broadcast channels

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

posibility to avoid a clone in try_recv

Licenser opened this issue · comments

Hi,
I've been looking into using async-broadcast and noticed that when calling try_recv on a channel the implementation always clones, I wonder if that is intent or accident?

If the limitation is made that new receivers only receive messages that were sent after they subscribed this could probably be avoided, reducing the clones needed to num_subscribers - 1. Given that cloning can be fairly expensive, this can lead to a nice performance improvement (especially for channels with a small number of receivers).

commented

@Licenser async-broadcast hasn't seen much optimizations yet, if you've found a location which you think can be optimized a PR for it would certainly be welcome! That also makes it easier to talk about the exact optimization (I've kind of forgotten how the code works), and if it works out we can probably merge it straight away!

Do you think you could open a PR for this?

Awesome :) I'll take a stab at it!

closing this thanks for the quick merge! <3 🚀