comm
comm copied to clipboard
Improve unbounded channels
I've added benchmarks and it turns out that comm channels are sometimes faster than stdlib channels. Unfortunately I messed up the commit message because I tried to use markdown syntax. Here is what it's supposed to look like:
# Where comm is faster than stdlib:
mpsc unbounded async_comm 45177
mpsc unbounded async_stdlib 51012
spsc bounded async_comm 16160
spsc bounded async_stdlib 19679
spsc bounded sync_large_comm 31155
spsc bounded sync_large_stdlib 67057
spsc bounded sync_mid_comm 52558
spsc bounded sync_mid_stdlib 68266
spsc bounded sync_small_comm 424309
spsc bounded sync_small_stdlib 544187
spsc one_space comm 7077
spsc one_space stdlib 8626
spsc unbounded async_comm 26718
spsc unbounded async_stdlib 30650
# Where comm is slower than stdlib
spsc unbounded sync_comm 36019
spsc unbounded sync_stdlib 29139
mpsc unbounded sync_comm 60856
mpsc unbounded sync_stdlib 44723
# Possible reasons
- Something in the sleep/wakeup handling: Maybe. But maybe not because
our sync stuff is faster in the bounded channels.
- Node caching: The stdlib reuses old nodes instead of allocating new
ones.
This is already looking quite good except for the unbounded+sync versions. Note that this doesn't touch Select and that the mpsc tests only test with two producers.
Cool! Maybe you should try to merge with the standard library? There seem to be mostly advantages over the current implementation.
I don't believe channels should be in the stdlib.