-
Notifications
You must be signed in to change notification settings - Fork 30
Allocate smaller nodes in unbounded channels #81
Comments
Note to self: we should probably grow nodes up to size 64 or 128, which improves performance quite a bit under high concurrency. |
I have an initial implementation for growing the
It calculates the Currently some tests do not finish (probably should add a cut-off time). I'll need to learn more about debugging in Rust in a multi-threaded environment to figure out what is going on. I committed it to a branch in case you have an idea for the failures. I can update here as I get a better handle on debugging! edit: Updated commit: https://github.com/kleimkuhler/crossbeam-channel/commit/7a6929c75bbd009e9f959de2b0f537f28abc659d... thank you @cynecx |
Oh, looks like we've been hit by undefined behavior again. :( Last time that happened was here: rust-lang/rfcs#1892 (comment) This is how I discovered the bug:
The problem is that we create values of type So, I suggest we change the message type from impl Slot<T> {
fn empty() -> Slot<T> {
Slot {
msg: UnsafeCell::new(None),
ready: AtomicBool::new(false),
}
}
} We can safely initialize Block {
start_index,
slots: (0..slot_count)
.map(|_| Slot::empty())
.collect::<Vec<_>>()
.into_boxed_slice(),
next: Atomic::null(),
} Some other parts of |
I have a new commit up (https://github.com/kleimkuhler/crossbeam-channel/commit/ba6b35ec4eef10c9b2cf41e65e8fc6aacbe2f7b7) after working out the changes required for avoiding the UB introduced by The issue I am addressing now is the failing crossbeam-channel/tests/list.rs Line 329 in da0980a
It can be replicated with I have tried a lot of different ways of dropping the Note:
still suffers from the same test failure. |
I left some comments in the commit you linked. Since |
If an unbounded channel is created for sending only one message, 31 of the initially allocated 32 slots won't be used at all.
The situation can be improved by starting with a single-slot node in the beginning and allocating exponentially larger nodes for further messages.
Perhaps we should also avoid allocating anything at all in the channel constructor. This might give us some performance wins in cases where no messages are sent through the channel.
Regarding interaction with #80, only nodes of size 32 should be recycled.
The text was updated successfully, but these errors were encountered: