JNI Performance?

You are here:

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

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.

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 ^^