[foreign] Some benchmarks for Foreign vs JNA (vs pure java implementation)

Lev Serebryakov lev at serebryakov.spb.ru
Mon Mar 11 14:32:17 UTC 2019


On 11.03.2019 17:17, Maurizio Cimadamore wrote:

 First of all, I didn't mean criticize Panama work in any way :-)

> 3) You seem to make the assumption that the natural way to encode
> input/outputs (see the FFTState class) is using Java arrays. Maybe an
  Yes, because I try to model situation when native library is used for
10% of work (it is almost impossible to re-create FFTW in Java, for
example), and 90% of [project-unique] work is done in pure Java, not
situation when JVM is used as glue to combine multiple native libraries.
I think, Java is not very good glue, anyway, but goor language to do
real work.

> actual Panama-based implementation will encode something like FFTState
> as an interface, which accessors to get at the result [i][j] - in a way
> that _no array at all is ever materialized_. This should even be better
> than JNA - where you have to have some backing java array for the output
> data (which requires GC activity). In other words, the main point of
> Panama array is to avoid materializing a true array - and expose access
> to underlying data lazily. Of course there are cases where people might
> just want to turn these into regular Java arrays, and perhaps these
> cases should be made more efficient (see below) - but it seem to me that
> forcing an impl to work in terms of Java arrays is missing half the
> point of using Panama array in the first place.
  Problem with all these non-materialized interfaces, that it is very
cumbersome to work with. If 90% of your processing code is calling
native interfaces via Panama (or JNA, for that matter), then you could
live with `SomeObject.get(i)` instead of `a[i]`, but, then, why do you
program in Java at all in this case?
  If you have 90% of processing in Java code,  and only 10% is passed to
special native library, then `z[i] = x[i] * alpha + y[i-1] * beta;` is
much more natural. Also, Java arrays have better optimizations (like
bounds check elimination) in HotSpot. It could be improved for all other
APIs (nio's buffers, Panama's Arrays) with intrinsics, but arrays are
still faster for Java-native processing.

-- 
// Black Lion AKA Lev Serebryakov



More information about the panama-dev mailing list