VALA 与 AOT 编译之间的性能差异?
我一直在用 Java 开发图像处理应用程序,但最近对 VALA 感兴趣。原因是因为我相信我可以提高应用程序的性能(我关心的主要是与C/C++库的互连,因为看起来<示例>在 Java 中使用 C/C++ 桥时存在性能损失)。
背景(我所知道的):
- VALA 转换为 C 代码,然后编译为本机机器代码。
- AOT(Java/Mono C#)也可以生成本机机器代码(而不是使用虚拟机,但仍然需要运行时捆绑包)。
- 在某些情况下,使用虚拟机甚至可以比本机机器代码更快(因为它可以通过 JIT 编译器进行优化)。
- 可以使用 VALA 生成可使用的 C/C++ 库。
有件事在我脑海中萦绕,但我找不到答案:
- 可以使用 AOT 编译器生成 C/C++ 使用库吗? (我想不是)。
- 生成的 AOT 二进制文件是否仍然存在桥接性能问题? (我想是的)。
- 在 VALA 中调用 C/C++ 库与从 C 中调用它们具有相同的性能吗? (我猜是的)。
有什么见解吗?
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:
- Can C/C++ consumable libraries be produced using an AOT compiler? (I guess not).
- Does the produced AOT binary, still has the bridge performance issue? (I guess it does).
- Calling C/C++ libraries in VALA has the same performance as calling them from C? (I guess it is).
Any insight?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1.可以使用 AOT 编译器生成 C/C++ 使用库吗?
这应该是不可能的,因为我们没有标头,而且 AOT 编译器创建的严格来说并不是 C 类,而只是机器代码。
(旁注:Java 类可以在 C/C++ 内部调用,但 AOT 编译器会生成单个二进制文件文件,我确信您无法从该文件外部访问您的 Java 类)。
答案:否
2。生成的 AOT 二进制文件是否仍然存在桥接性能问题?
首先,我们需要知道:如果使用桥接器(如 JNI、javacpp 等)从 Java 调用任何 C/C++ 类,总会导致性能损失?
根据 ##[电子邮件受保护] 中的“W_”:
但由于我使用 JavaCV 作为 OpenCV 库的桥梁,它使用了几种类型的对象,如果上述情况属实,它应该会影响性能。
因此,AOT 编译可能会稍微加快执行速度,但仍然必须经过桥并进行类型转换,这可能是合乎逻辑的。
答案:是(但可能会稍微快一些)
3。在 VALA 中调用 C/C++ 库与从 C 调用它们具有相同的性能?
由于它直接转换为 C,我看不出有什么理由不这样做。此功能由 #[email protected] 中的“nemequ”支持:
答案:是
我仍然不知道为什么“有人”投票结束我的问题,而他/她甚至懒得对此发表评论。
我认为这些问题/答案足够有建设性(正如 pst 评论的那样),它们可能对刚接触 VALA 或 AOT 编译器的其他人有所帮助。
如果我的结论不正确请纠正我。
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]:
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]:
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.