A quick jni4net performance hack
jni4net is a great library that creates Java proxies for Microsoft based C# libraries on the Windows platform. It makes Java JNI easy with good performance. You follow this processes to use jni4net
I found a quick hack that improves the performance of the jni4net bridge that involves inserting a line of code in each generate C# method. This hack improves the Java-to-DLL call time only. It does not impact the performance of the Java code on one side or the C# code on the other. It lowers the overhead of highly repetitive method calls by up to 100x for methods with no type marshaling. Each method looks something like this:
I add one line of code that makes the method look like this:
This Powershell script modifies all jni4net generated methods to add the code shown above. You can also find the script on github :
...
- Create your C# library
- Run proxygen to generate Java native library source code and C# adapter source that shims in between Java and the original library.
- Run javac to compile the java code
- Create a jar file of the compiled java code
- Run the .Net csc.exe that comes with the default .Net installation to compile the C# code
- Create a new DLL of the just compiled C# code
- Create a Java program that uses the new generated Jar file, the generated C# dll and the original C# dll.
I found a quick hack that improves the performance of the jni4net bridge that involves inserting a line of code in each generate C# method. This hack improves the Java-to-DLL call time only. It does not impact the performance of the Java code on one side or the C# code on the other. It lowers the overhead of highly repetitive method calls by up to 100x for methods with no type marshaling. Each method looks something like this:
I add one line of code that makes the method look like this:
This Powershell script modifies all jni4net generated methods to add the code shown above. You can also find the script on github :
...
These are great instructions for quick Jni4net performance improvement. All the essential info is there and I've good time studying such awesome demonstration. Thanks.
ReplyDeletegreat
ReplyDelete