[std.concurrency] prioritySend is 1000 times slower than send?

Sean Kelly sean at invisibleduck.org
Fri Oct 8 14:29:32 PDT 2010


== Quote from Sean Kelly (sean at invisibleduck.org)'s article
> Sean Kelly Wrote:
> > osa Wrote:
> >
> > > 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.
> >
> > Thanks for this.  I can tell you that prioritySend performs an extra allocation to account for a design requirement (if a priority message isn't received it's
thrown as PriorityMessage!(T), and this exception is generated when the send occurs, since static type info isn't available at the receive side when it's needed
for this).  I had originally thought that the difference was just more garbage collections, but calling GC.disable only increases the number of priority messages
sent by about 1000.  I'll have to look at the code to see if I can figure out what's going on.
> Okay, I've fixed one issue with priority messages that, aside from broken behavior, has increased performance somewhat.  Here are the timings:
> Benchmark: 5944400 iterations in 5 seconds (1.18888e+06/second) -- built without -version=priority
> Benchmark: 4900 iterations in 5.119 seconds (957.218/second) -- build with -version=priority before fix
> Benchmark: 39700 iterations in 5.001 seconds (7938.41/second) -- built with version=priority after fix
> The remaining issue has to do with the fact that the exception is constructed when the send is issued and when this exception is constructed a stack trace is
generated as well.  I'll have to modify Throwable so that derived classes can specify that no trace be generated.  That or eliminate constructing the exception at
the send site and change how that exception is represented.

I just made some functional changes to how priority messages are sent and added a few performance tweaks to messaging in general.  The only visible
difference should be that PriorityMessageException is no longer a template class but instead contains a Variant, which is something that would have been
necessary for inter-process messaging anyway.  Here are the timings:

--- Before ---

$ dmd -inline -release -O priority
Benchmark: 5749600 iterations in 5 seconds (1.14992e+06/second)
Benchmark: 5747800 iterations in 5 seconds (1.14956e+06/second)
Benchmark: 5748200 iterations in 5 seconds (1.14964e+06/second)

$ dmd -inline -release -O priority -version=priority
Benchmark: 39100 iterations in 5.01 seconds (7804.39/second)
Benchmark: 39100 iterations in 5.01 seconds (7804.39/second)
Benchmark: 39100 iterations in 5 seconds (7820/second)

--- After ---

$ dmd -inline -release -O priority
Benchmark: 7204200 iterations in 5 seconds (1.44084e+06/second)
Benchmark: 7167000 iterations in 5 seconds (1.4334e+06/second)
Benchmark: 7164400 iterations in 5 seconds (1.43288e+06/second)

$ dmd -inline -release -O priority -version=priority
Benchmark: 7442500 iterations in 5 seconds (1.4885e+06/second)
Benchmark: 7448600 iterations in 5 seconds (1.48972e+06/second)
Benchmark: 7421800 iterations in 5 seconds (1.48436e+06/second)


More information about the Digitalmars-d mailing list