smol-rs / async-broadcast

Async broadcast channels
Apache License 2.0
160 stars 26 forks source link

posibility to avoid a clone in try_recv #18

Closed Licenser closed 2 years ago

Licenser commented 2 years ago

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).

yoshuawuyts commented 2 years ago

@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?

Licenser commented 2 years ago

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

Licenser commented 2 years ago

closing this thanks for the quick merge! <3 🚀