digitalmars.D - [std.concurrency] prioritySend is 1000 times slower than send?
- osa <osa aso.osa> Sep 29 2010
- "Steven Schveighoffer" <schveiguy yahoo.com> Sep 29 2010
- "Denis Koroskin" <2korden gmail.com> Sep 29 2010
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.
Sep 29 2010
On Wed, 29 Sep 2010 14:25:07 -0400, osa <osa aso.osa> wrote: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.
Note, core.demangle will probably soon replace std.demangle, and is actively being developed. You may need to download the svn version of druntime. ref: http://lists.puremagic.com/pipermail/phobos/2010-September/002376.html -Steve
Sep 29 2010
On Wed, 29 Sep 2010 22:31:53 +0400, Steven Schveighoffer <schveiguy yahoo.com> wrote:On Wed, 29 Sep 2010 14:25:07 -0400, osa <osa aso.osa> wrote: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.
Note, core.demangle will probably soon replace std.demangle, and is actively being developed. You may need to download the svn version of druntime. ref: http://lists.puremagic.com/pipermail/phobos/2010-September/002376.html -Steve
IIRC, core.demangle is already in dmd2.049 (i.e. no need for an svn version unless there are significant changes in core.demangle in trunk).
Sep 29 2010









"Steven Schveighoffer" <schveiguy yahoo.com> 