3 ms·
JNI: fast but tedious JNA: comfortable but slow Panama: comfortable & fast
by MrBuddyCasino 3y ago
JNI: fast but tedious
JNA: comfortable but slow
Panama: comfortable & fast
- matheusmoreira 3y agoWhat is it about JNA that makes it slow? What is it about Panama that makes it fast? Soon I'll start working on similar features for my own language. This could give me a massive head start.
- pjmlp 3y agoPanama is part of the runtime, it can be made to make the best use of that knowledge. JNA relies on JNI, and exposes a better Java interface.
- fweimer 3y agoAs far as I understand it, with JNA, all calls into C code go through libffi: https://github.com/java-native-access/jna/blob/master/www/FunctionalDescription.md https://github.com/java-native-access/jna/blob/master/www/Fu... This means that every call sets up some libffi data structures and libffi uses this information to perform the native call. Likewise in the other direction for return values. With JNI (and Panama), Hotspot can directly emit the argument/return code a the call, not too dissimilar from what a C or C++ compiler would do. There is still some overhead from maintaining JVM invariants. For example, I think a thread blocked in an FFI call can still participate in a safepoint. But that applies to JNI as well.