[foreign] Poor performance?
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Fri May 17 10:26:46 UTC 2019
On 17/05/2019 06:54, Samuel Audet wrote:
> Hi,
>
> This person seems to be unable to obtain an acceptable level of performance
> with Panama:
> https://github.com/zakgof/java-native-benchmark
>
> I thought it would be good to know why so this can be fixed!
Hi Samuel,
thanks you for bringing this up, I saw this benchmark few days ago and I
took a look at it. That benchmark is unfortunately hitting on a couple
of (transitory!) pain points: (1) it is running on Windows, which lacks
the optimizations available for MacOS and Linux (directInvoker). When
the linkToNative effort will be completed, this discrepancy between
platforms will go away. The second problem (2) is that the call is
passing a big struct (e.g. bigger than 64 bits). Even on Linux and Mac,
such a call would be unable to take advantage of the optimized invoker
and would fall back to the so called 'universal invoker' which is slow.
The plan is to start using linkToNative as our official cross-platform
fast-path, and then progressively enhance linkToNative so that it can
handle all the cases that are currently left to universalInvoker - of
these there are two that are important: big structs passed by pointer,
and return value in memory. Once this is done (and this is mostly a
matter of figuring out a 'private protocol', or set of carriers that are
known to both the Panama binder and the VM), then I would expect that
performance cliffs like the one you show will go away.
At present state, on Linux and Mac, I would expect a call involving
small structs and/or primitive to be on par with JNI and be
significantly faster than JNI/JFFI. Luckily, when writing real world
code, these things usually cancel out - e.g. it would be unusual for a
real world application to only have 'slow' calls with big structs, but
the situation is of course possible in a synthetic benchmark and we
should make sure to polish these edges.
Thanks
Maurizio
>
> Samuel
More information about the panama-dev
mailing list