1

I am building an Android app that integrates with a 3rd party library that is provided as a native library (.so file).

The app would need to use functionality from the native library at around 0-30 JNI calls per second.

Although the function calls are non-blocking and return almost immediately, i am wondering whether this design should be avoided to begin with, or the overhead of frequent JNI calls in practice can be used?

I have read a similar question here: What makes JNI calls slow?

But besides that, i couldn't find too many numbers regarding JNI performance.

Community
  • 1
  • 1
lysergic-acid
  • 19,570
  • 21
  • 109
  • 218

1 Answers1

2

On a device I looked at a couple years back, calling an empty static no-arg method in Java took 56ns, while calling the same through JNI took about 250ns. (Calls got a bit slower in Ice Cream Sandwich -- was 200ns in Honeycomb.)

People tend to fixate on the "it's 5x as expensive" part. What matters for your application is that the 30 JNI calls would incur less than 8 microseconds of overhead.

It's not worth worrying about unless you're calling it thousands (or tens of thousands) of times per second.

fadden
  • 51,356
  • 5
  • 116
  • 166