[concurrency-interest] question from new-user/instructor: "x.fork(); x.join()" vs. x.compute()

Doug Lea dl at cs.oswego.edu
Mon Mar 15 09:24:39 EDT 2010

On 03/14/10 20:00, Dan Grossman wrote:

> There is jitter in the numbers, for example, the sequential is sometimes
> 47 or 63, but ballpark the FORK-false gets about 1.5-2x faster after
> warmup and the FORK-true gets about 3-4x faster after warmup. So the 40x
> difference drops to about a 20x-25x difference. That still seems like a
> lot -- higher than the overhead of the fork and join calls and not due
> to warmup.

About 3X of the difference is due to hotspot optimization.
With a non-opaque call to compute(), it unrolls some recursion
which can inline leaf calls. (The resulting machine code
is so different with this change that it is hard to tell it
is almost the same source code). Which gets you back to the
estimated plain fork/join vs call overhead.

>> Yes, this is a problem. We are working on it.
>> You might have seen even more extreme results because current
>> uncommitted version addresses some of this.
> If a newer version is Java 1.6 friendly and stable for these simple
> sorts of programs, I'd be happy to try it out.

I'll be checking in a substantial update to the "jsr166y" versions
hopefully sometime this week, which we'll let settle
before pushing it into openjdk7.


More information about the Concurrency-interest mailing list