简体   繁体   中英

Is JNI a solution to increase bit manipulation performance?

I have a java class that does really heavy bit decoding and manipulation. This class accounts to almost 96% of my total app's execution time. I was wondering whether if I write some c code for these bit manipulation and use java native methods to load the c libraries, will I get significant increase in my performance?

找出问题的唯一真正方法是使用专用Java基准测试工具进行仔细的基准测试(我想到了Caliper) ,但是我个人怀疑您是否会获得足够的性能以超过JNI开销。

As mentioned by Louis, the best way to know is to measure. The overhead of calling through JNI is significant. The better question to ask is if you are calling your methods frequently. In other words, to consume 96% of the execution time, does your bit manipulation method get called thousands of times per second or does it do significant work in a single call? If it's the latter, then it's highly likely that you will benefit from native code.

The only way I could see JNI/native code being faster is you can overcome the JNI call overhead by passing a large dataset to the native method for it to bit manipulate. Note that unlike Java methods, JNI methods cannot be inlined/optimized by hotspot. Native calls require copying values back and forth between the Java and Native memory areas.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM