Peter Mortensen 1, 2 2 gold badges 12 12 silver badges 14 14 bronze badges. Sorter Sorter 2 2 gold badges 4 4 silver badges 11 11 bronze badges. This has come over and over again and the answer keeps being that no. Also do you like rewriting werking code? If it can improve speed significantly and save some memory, then yes. Performance optimization is almost always case specific, you expect to find "general answers" where there are only specific ones.
This is a good question. Show 2 more comments. Active Oldest Votes. Improve this answer. Community Bot 1. Random42 Random42 It was one of those "seemed like a good idea at the time" things. We thought that we'd get both portability and performance. We ended up getting very little of the former and none of the latter.
If we had it to do over, we'd have just rewritten it in Java. I am not fully sure of the reasons behind it yet still exploring but this has been the experience when doing image processing in Android. Add a comment. Here's the gist of it all: 1. I know that 'crossing boundaries' when making a JNI call in Java is slow.
What does the underlying jvm implementation do when making a JNI call that makes it so slow? Causes include:,Java Strings are objects, have length and are encoded. Accessing or creating a string may require an O n copy. It is worth mentioning that not all Java methods marked with native are "slow". Some of them are intrinsics that makes them extremely fast. If you add any files,it will delete all existing files related to this answer- only this answer.
Tech Community Register Log in. Asked in community. What makes JNI calls slow? Question What makes JNI calls slow? I know that 'crossing boundaries' when making a JNI call in Java is slow. There are many more details outlined in this paper If you are interested in benchmarking JNI vs native code this project has code for running benchmarks. Causes include: Native methods will not be inlined by the JVM. Nor will they be just-in-time compiled for this specific machine -- they're already compiled.
A Java array may be copied for access in native code, and later copied back. The cost can be linear in the size of the array. I measured JNI copying of a , array to average about 75 microseconds on my Windows desktop, and 82 microseconds on Mac. If the method is passed an object, or needs to make a callback, then the native method will likely be making its own calls to the JVM.
0コメント