[r-t] Writing method display software

Ian Partridge ian at poncho.org.uk
Mon Nov 30 15:12:42 UTC 2015


On 30 November 2015 at 14:50, Don Morrison <dfm at ringing.org> wrote:
>
> On Sun, Nov 29, 2015 at 10:29 AM Richard Smith <richard at ex-parrot.com> wrote:
> > it is hard to compare C++ with Scala as one compiles to native
> > machine code and the other to Java bytecode.
>
> Though modern, high performance JVMs then JIT compile the bytecode down to machine code, anyway, right?

Yes, all modern JVMs include a JIT compiler.  Java performance is
terrible without one.  Modern JITs are comparable to, and sometimes
better than, static compiler a la C/C++.  Because they can profile the
application at runtime they can make better optimisation choices than
a static compiler can.

> I suspect that with Scala, just as with the Lisp I love and use regularly, one of the
> important considerations is to avoid allocating and then GCing too much memory
> in inner loops.

Yes.  Small objects with local scope (as determined by escape
analysis) are generally stack-allocated and never end up on the Java
heap anyway.  But larger objects or larger numbers of small objects
will necessarily cause heap allocations.  Allocating to the heap is
generally fast though, as the days of global heap locks are long gone.
JVMs, like malloc, use thread-local subheaps to reduce heap
contention.

> Though modern GCs can be surprisingly good at dealing with short lived objects at
> minimal cost, so much so that in some cases standing on your head to avoid consing
> can reduce locality to such an extent that it actually makes things worse, though I
> don't think I've ever run into such a problem in any ringing software whose performance
> I've worried about (which is pretty much just search, nothing else I've ever dealt with
> in ringing being all that sensitive to performance).

Many GCs are "generational":  they reserve specific portions of the
heap for new objects, then focus the GC on collecting those areas more
frequently.  This reduces the overall cost of GC, as most objects die
young.

I think Scala+JVM is an excellent combination for writing ringing code
nowadays.  Scala's expressiveness and functional features, plus the
JVM's years of JIT+GC development makes it a strong platform.

-- 
Ian Partridge (day job: support/development for IBM's JVM)




More information about the ringing-theory mailing list