Performance differences between VALA vs AOT compilations?
Asked Answered
P

1

11

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?

Prelect answered 16/1, 2012 at 2:38 Comment(2)
This question seems focused enough to "be constructive"; or at least linked and closed to duplicates.Gusty
Sorry my English may not be that good. I'm not sure why was voted to be closed. Thanks pst for upvoting.Prelect
P
6

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.

Prelect answered 17/1, 2012 at 3:2 Comment(1)
I think everything is right, except that Vala uses gobject, and gobject is known to be heavy both in constructing instances and keeping reference counts. Though I personally prefer reference counting for its determinism over tracing garbage collectors.Dreyfus

© 2022 - 2024 — McMap. All rights reserved.