Oh, my GoD! Goroutines on D

Jin nin-jin at ya.ru
Mon Jun 15 09:09:23 UTC 2020


On Monday, 15 June 2020 at 01:55:27 UTC, mw wrote:
> On Sunday, 14 June 2020 at 22:57:25 UTC, Jin wrote:
>> My wheels are quite simple: 
>> https://github.com/nin-jin/go.d/blob/master/source/jin/go/queue.d
>>
> ...
>> received 100000000 messages in 10011 msec sum=4999999950000000 
>> speed=9989 msg/msec
>
> Since you are using 1-provider-1-consumer queue, can you try 
> this package as a drop-in replacement in go.d:
>
> https://github.com/MartinNowak/lock-free/blob/master/src/lock_free/rwqueue.d
>
> (you may need to add align() to that implementation).
>
> according to my test:
>
> received 1000000000 messages in 9845 msec 
> sum=499999999500000000 speed=101574 msg/msec
>
> you may get ~10x boost.

I have added a new release and a PR to your repo.

But I don't think it's a good idea to replace jin.go.queue by 
lock_free.rwqueue because:

1. My API is std.range compatible.
2. I use the same API for queue and channels.
3. My API supports finalization (by provider or consumer or both).
4. Your queue is fixed size. But my channels operate with set of 
queues that can have different sizes.

But I would steal some optimization:

1. Power of 2 capacity and bitop instead of division. It can add 
10% performance.
2. The cache line size should be a minimum size of the message to 
prevent false sharing.

You are using atomicLoad!(MemoryOrder.acq) at there: 
https://github.com/MartinNowak/lock-free/blob/master/src/lock_free/rwqueue.d#L41
Is this really required? CPU can't reorder dependent statements.






More information about the Digitalmars-d mailing list