I started using std.concurrency in some projects and overall it feels like a solid (albeit minimalistic) design. However, current implementation has some issues. For example, I've noticed that using prioritySend slows everything considerably. Here is a simple benchmark to demonstrate the problem:
---------
import std.concurrency;
import std.date;
import std.stdio;

struct Message {}

void main() {
    enum TIME_LIMIT = 5 * ticksPerSecond;
    auto started = getUTCtime();
    d_time running = 0;
    long iterations = 0;

    while( running < TIME_LIMIT ) {
        version( priority ) {
            prioritySend( thisTid, Message() );
        }
        else {
            send( thisTid, Message() );
        }
        receive( (Message){} );
        if( ++iterations % 100 == 0 ) {
            running = getUTCtime() - started;
        }
    }

    auto seconds = cast(double)running / ticksPerSecond;
writeln( "Benchmark: ", iterations, " iterations in ", seconds, " seconds (", iterations / seconds, "/second)" );
}
---------

Using dmd v2.049 on linux, this produces:
        Benchmark: 4469600 iterations in 5 seconds (893920/second)

But when compiled with -version=priority, result is quite different:
        Benchmark: 3700 iterations in 5.177 seconds (714.7/second)

This is about 1250 times slower than using send! Is there any reason for such penalty for using prioritySend?

Note that benchmark code is single-threaded. Initial version was using two threads (with similar discrepancy between send and prioritySend) but when I've tried to run it after compiling with -profile, it did not work. I assume that profiling is not supported for multi-threaded programs yet? So I profiled single-threaded benchmark and it seems that the main offender is PriorityMessageException constructor:
  Num          Tree        Func        Per
  Calls        Time        Time        Call

1700 777986427 777986427 457639 class std.concurrency.PriorityMessageException!(struct concur1.Message).PriorityMessageException std.concurrency.PriorityMessageException!(struct concur1.Message).PriorityMessageException.__ctor(struct concur1.Message)

P.S. demangle program example at http://www.digitalmars.com/d/2.0/phobos/std_demangle.html is broken -- it does not compile.

P.P.S. std.demangle fails for some symbols, for example:
        _D3std5array13__T5emptyTyaZ5emptyFNdxAyaZb
        
_D3std6format19__T10FormatSpecTyaZ10FormatSpec6__ctorMFNcxAyaZS3std6format19__T10FormatSpecTyaZ10FormatSpec
and many other.

Reply via email to