Performance considerations
JCOBridge gives the .NET developer a simple and direct way to write code that runs inside the JVM. With the Dynamic Language Runtime of .NET you can write code as if you were writing Java. The subsystem translates every request into the JVM context, executes it there and returns the result.
Dynamic execution
Dynamic code in C# simplifies the coding and results in "writing Java code in C# files":
double a = 2;
double b = 3;
double c = Math.PI/2;
/* Dynamic code */
JVM.ImportPackage("JavaClass");
var jCInstance = DynJVM.JavaClass.@new();
var result = jCInstance.add(a, b);
var sin = jCInstance.sin(c);
With dynamic access you do not need to call Invoke to execute Java code: you simply call the Java method.
Direct execution
The following snippet obtains the same results with the direct interfaces:
double a = 2;
double b = 3;
double c = Math.PI/2;
/* Not dynamic code */
JVM.ImportPackage("JavaClass");
IJavaObject jCInstance = JVM.New("JavaClass") as IJavaObject;
double result = (double)jCInstance.Invoke("add", a, b);
double sin = (double)jCInstance.Invoke("sin", c);
The results of the two snippets are equivalent.
Performance
Dynamic code is clearer and easier to use, but it comes at a price: the dynamic object has to work out the meaning of the syntax after every dot, and that search consumes resources.
Code based on direct interfaces is more complex to write and less intuitive, but in situations like the one above it is about 250x faster.
You can ignore the gain if you call only a few objects or methods, but it matters when you make thousands of calls.
For current latency figures, see the performance benchmarks.
Evolution
JCOBridge includes classes that help you interact with the JVM through the direct interfaces. The JNet GitHub repository contains the Java SE classes managed with this paradigm.