Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance differences between VALA vs AOT compilations?

Tags:

java

c#

vala

aot

I have been developing an image processing application in Java but I have been recently interested in VALA. The reason is because I believe I can increase the application performance (my concern is mainly in the interconnection with C/C++ libraries, as it seems <Example> that there is a performance punishment when using C/C++ bridges in Java).

Background (what I know):

  • VALA translates into C code and then its compiled to a native machine code.
  • AOT (Java/Mono C#) can produce native machine codes as well (instead of using VMs, but still requires the runtime bundle).
  • In some cases using a VM, can be even faster than a native machine code (as it can be optimized through the JIT compiler).
  • Consumable C/C++ libraries can be produced using VALA.

There is something that is going around my head and I can't find the answer:

  1. Can C/C++ consumable libraries be produced using an AOT compiler? (I guess not).
  2. Does the produced AOT binary, still has the bridge performance issue? (I guess it does).
  3. Calling C/C++ libraries in VALA has the same performance as calling them from C? (I guess it is).

Any insight?

like image 381
lepe Avatar asked Jan 16 '12 02:01

lepe


1 Answers

1. Can C/C++ consumable libraries be produced using an AOT compiler?

It should not be possible as we have no headers and it is not strictly a C class what the AOT compiler is creating but just machine code.

(Side note: Java classes can be called inside C/C++, but as AOT compilers produces a single binary file, I'm sure you can not access your Java classes from outside that file).

Answer: NO

2. Does the produced AOT binary, still has the bridge performance issue?

First, we need to know: if calling any C/C++ class from Java using a bridge (like JNI,javacpp,etc.) will always result in a performance loss?

According to "W_" from ##[email protected]:

it depends on how you're calling it (e.g. if arguments have to be converted and such). Just calling out to a library function without any arguments or return type conversion shouldn't take any different time than it does in any C app.

But as I'm using JavaCV as bridge for OpenCV library, it uses several type of objects which, if the above is true, it should affect the performance.

So, it may be logical that AOT compilation may speed-up a little bit the execution but still has to go through the bridge and do the type conversion.

Answer: YES (but may be slightly faster)

3. Calling C/C++ libraries in VALA has the same performance as calling them from C?

As it converts directly to C, I don't see a reason why not. This was supported by "nemequ" from #[email protected]:

pretty much, yes. vala has a habit of using temporary variables, but that's exactly the sort of thing most compilers can easily optimize away. if you're using gcc, pass -O2 and you should be good.

Answer: YES

Still I don't know why "someone" voted to close my question and he/she didn't even bothered to comment about it. I think these questions/answer are constructive enough (as pst commented) and they may be helpful for other people that are new to VALA or AOT compilers.

If my conclusions are not correct please correct me.

like image 177
lepe Avatar answered Nov 13 '22 18:11

lepe