Skip to main content

JNI Performance?

4 replies [Last post]
ted_graham
Offline
Joined: 2007-11-14

We have a C++ DLL that we need to talk to using JNI, and I'm curious about the expected performance impact.

Throughput is not a big deal, we will have less than 100 calls/second into and out of the DLL, and the processing time in the DLL should be sub millisecond. Each call in and out will likely have 20-200 bytes of payload.

However, latency is very important in this application. Does anyone have any benchmarks for JNI performance? Specifically as to what latency impact we might expect.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
linuxhippy
Offline
Joined: 2004-01-07

I did some benchmarking some time ago, sorry I don't have the results here right now.

A general rule is that Java->C method calls are quite fast, on my Core2Duo a simple method with one int-parameter took ~30 cycles, the JVM is well tuned for this case.
So if you e.g. copy your payload into a native ByteBuffer, just hand that over to the C-routine along with some primitive parameters you should not even notice JNI overhead.

However C->Java calls, as well as SetField and compareable operations are quite slow, also the array-critical functions are quite heavy.

- Clemens

ted_graham
Offline
Joined: 2007-11-14

Thanks for the information. I'm connecting to a 3rd party API that is provided as a C++ library, so I don't get to define what data is passed across.

Anyone else have numbers about the performance cost of calling into a C++ DLL with ~100 bytes of data, or of the cost of getting called back from the DLL with a 100 byte payload?

peter__lawrey
Offline
Joined: 2005-11-01

> I don't get to define what data is passed across.
You can write some C++ code which does instead. Something like:

Java <=> your C++ code <=> the DLL.

linuxhippy
Offline
Joined: 2004-01-07

Well the main problem is your question is a bit vague.
JNI performance depends on a lot of factors, and there are many different way of passing "payload" arround, whith quite different use-cases / performance characteristics.

However all in all, you shouldn't face any problems by using JNI. Its quite optimized, and even the not as optimized C->Java case I am quite sure it will fit your needs. JNI won't add a ms latency ^^