commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Steitz <phil.ste...@gmail.com>
Subject [math] Thread-safety and initialization overhead in distribution sample() methods
Date Wed, 08 Oct 2014 00:38:34 GMT
Comments in MATH-1154 (bad performance in test code) and the
now-reopened MATH-1124 (slow initialization) point to the need to
fix the problem we created when we moved sample() to the
distribution classes with PRNG provided by a final field with
default implementation initialized by the constructor.  Several
suggestions have been made to improve things.

0) require that sample() take a RandomGenerator as an additional
parameter
1) improve initialization performance of the default RandomGenerator
2) Replace the default with a generator with negligible
initialization latency
3) Make either PRNG initialization or initialization of the
RandomGenerator field lazy

I may have missed some.  One thing to note is that the (default)
Well generators are *not* threadsafe, so having things final,
avoiding lazy init is not really buying us anything in the current
setup.  So unless 2) is done with a threadsafe generator, only 0)
really makes sample() threadsafe (assuming the caller protects the
instance that needs to be re-supplied on each call).

I am +0 for adding a new method that takes a generator as an
additional actual parameter, but as a user I like the convenience of
just calling sample().  I never use distributions as singletons, so
the lack of threadsafety does not concern me.  It seems then that a
reasonable approach might be to add the new method, keep the old one
but move to lazy initialization with documentation that when you use
the default, the provided PRNG it is not threadsafe.  I would also
obviously be in favor or anything we can do in 1).

Phil




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message