VALA 与 AOT 编译之间的性能差异?

发布于 2024-12-27 07:42:12 字数 608 浏览 5 评论 0原文

我一直在用 Java 开发图像处理应用程序,但最近对 VALA 感兴趣。原因是因为我相信我可以提高应用程序的性能(我关心的主要是与C/C++库的互连,因为看起来<示例>在 Java 中使用 C/C++ 桥时存在性能损失)。

背景(我所知道的):

  • VALA 转换为 C 代码,然后编译为本机机器代码。
  • AOT(Java/Mono C#)也可以生成本机机器代码(而不是使用虚拟机,但仍然需要运行时捆绑包)。
  • 在某些情况下,使用虚拟机甚至可以比本机机器代码更快(因为它可以通过 JIT 编译器进行优化)。
  • 可以使用 VALA 生成可使用的 C/C++ 库。

有件事在我脑海中萦绕,但我找不到答案:

  1. 可以使用 AOT 编译器生成 C/C++ 使用库吗? (我想不是)。
  2. 生成的 AOT 二进制文件是否仍然存在桥接性能问题? (我想是的)。
  3. 在 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:

  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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十秒萌定你 2025-01-03 07:42:12

1.可以使用 AOT 编译器生成 C/C++ 使用库吗?

这应该是不可能的,因为我们没有标头,而且 AOT 编译器创建的严格来说并不是 C 类,而只是机器代码。

(旁注:Java 类可以在 C/C++ 内部调用,但 AOT 编译器会生成单个二进制文件文件,我确信您无法从该文件外部访问您的 Java 类)。

答案:否

2。生成的 AOT 二进制文件是否仍然存在桥接性能问题?

首先,我们需要知道:如果使用桥接器(如 JNI、javacpp 等)从 Java 调用任何 C/C++ 类,总会导致性能损失?

根据 ##[电子邮件受保护] 中的“W_”:

这取决于你如何调用它(例如,如果参数必须是
转换等)。
只需调用库函数,无需任何参数或返回
类型转换所花费的时间不应与任何类型转换所花费的时间不同
C 应用程序。

但由于我使用 JavaCV 作为 OpenCV 库的桥梁,它使用了几种类型的对象,如果上述情况属实,它应该会影响性能。

因此,AOT 编译可能会稍微加快执行速度,但仍然必须经过桥并进行类型转换,这可能是合乎逻辑的。

答案:是(但可能会稍微快一些)

3。在 VALA 中调用 C/C++ 库与从 C 调用它们具有相同的性能?

由于它直接转换为 C,我看不出有什么理由不这样做。此功能由 #[email protected] 中的“nemequ”支持:

差不多,是的。 vala 有使用临时变量的习惯,但是
这正是大多数编译器可以轻松优化的事情
离开。如果你使用 gcc,通过 -O2 就可以了。

答案:是

我仍然不知道为什么“有人”投票结束我的问题,而他/她甚至懒得对此发表评论。
我认为这些问题/答案足够有建设性(正如 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]:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文