Rewrote chameneos_redux
.
Well, actually I dropped the first rewrite 'cause it was too slow.
...And the second rewrite, since that was still too slow and used a ton of unsafe
.
I guess this is the third rewrite plus a bit, since it took a lot of mauling to get it into shape.
The problem is that the competition is really good. The C++ uses a thread pool, you see.
But to make it fast, they used a really biased selection algorithm... and then just spawned enough threads to hide the bias. The C version doesn't use a thread pool, but it deals with the meeting count in the same atomic instruction as the mall exchange. And both of them do unsynchronized cross-thread writes...
But, I'm glad to say, a lot of elbow grease later and I'm pretty sure I've soundly beaten both.
Advantages
It uses a Java-like thread pool. Except mine is atomic and can only actually hold 7 threads - the other 3 must be active or in the mall lest they just disappear. A form of juggling, perhaps. And when I say atomic I mean it - in the best case it can atomically dequeue a task, add it to an empty mall and switch into a fresh thread in a single exchange. After a meeting, it'll enqueue both tasks and dequeue the next in another single exchange.
I use no unsafe at all, relying instead on gratuitously tuned uncontested atomics. A lot of assembly has been read to make sure of that status.
My timings put this roughly 2-3x the speed of the next-best competitor. I have no doubt other people's timings will be slightly different, but I'm pretty confident in the lead. I can actually make it a bit faster by dropping the number of executor threads - unlike C++ I don't need one per virtual thread to hide bias, and unlike the Java I don't have contention problems with fewer threads. However, I thought that might get me into trouble, so I didn't. I might mention it when I submit it, though.
Disadvantages
let x = || Default::default();
let mut states: [ChameneosState; 16] = [
x(), x(), x(), x(), x(), x(), x(), x(),
x(), x(), x(), x(), x(), x(), x(), x(),
];
PS: help me i can't stop