smol-rs / async-broadcast

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

Avoid clode for the last recv of a message #19

Closed Licenser closed 2 years ago

Licenser commented 2 years ago

This removes the clone mentioned #18 for try_recv if we are the last receiver reading a message that would move the queue forward.

It also adds two benchmarks (one sender, one receiver) and (one sender two receivers) to measure this. The benchmark is not perfect as it uses simple_features as well as a copy-able payload (the best possible case for the old code) the results were still encouraging.

For 1->1 it showed a 1% drop in performance for 1->2 it showed a 9% improvement in perforamcen

that seems worth it as we'll likely see much bigger improvements for more complex data structures that need to be cloned instead of copied.

zeenix commented 2 years ago

@Licenser Thanks so much for this great contribution! :+1: The actual changes look good to me, so I only have nitpicks about non-functional aspects. :) Apart from the comments on the commit:

Otherwise, looks really great.

Licenser commented 2 years ago

:+1: split it out into two commits and added some additional text to them

zeenix commented 2 years ago

+1 split it out into two commits and added some additional text to them

Awesome! That was quick. Just one more split and we're good to go. :)

Licenser commented 2 years ago

Ohh, sorry I didn't understand what you meant, the changes on the Cargo.toml were VSCode being eager :) I reverted them as I didn't mean to change the Cargo.toml aside from the addition of benchmarks and the new dependency. Hope this looks good now

zeenix commented 2 years ago

Many thanks @Licenser !