本机 Erlang 模块和字节码 Erlang 模块之间的性能差异是什么?

发布于 2024-08-22 01:22:37 字数 44 浏览 3 评论 0原文

本机 Erlang 模块和字节码 Erlang 模块之间的性能差异是什么?

What is the performance difference between native and bytecode Erlang modules?

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

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

发布评论

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

评论(5

烟─花易冷 2024-08-29 01:22:37

对于实际上执行大量工作的代码(而不是花费大部分时间等待消息或调用内置函数),典型的加速将在 8 到 20 倍之间。

这在很大程度上还取决于代码的具体功能:浮点运算循环或二进制/位串操作往往会获得最佳加速,而更正常的元组和列表操作代码可能不会超过 8-10 倍快点。

另外,请记住,如果循环体主要调用未编译为本机代码的其他模块,则编译为本机代码的循环不会更快。

(我已经有一段时间没有查看新的基准测试结果了,但我认为没有发生太大变化。)

For code that actually does a lot of work (as opposed to spending most of its time waiting for messages or calling built-in functions), typical speedups would be between 8 and 20 times.

This also depends a lot on exactly what the code does: loops over floating point operations or manipulation of binaries/bitstrings tend to get the best speedups, while more normal tuple-and-list-manipulating code might not get more than 8-10 times faster.

Also, keep in mind that a loop compiled to native code will not be much faster if the loop body is mainly calling other modules that are not compiled to native.

(It's been a while since I looked at fresh benchmark results, but I don't think a lot has changed.)

哎呦我呸! 2024-08-29 01:22:37

已经有一些正确的答案,但我认为您实际上需要测量特定功能的性能。如果关键区域比字节码版本相当快,则可能仍然需要清理模块以使其故障安全。

There are a few correct answers already, but I think you would actually need to measure the performance of your particular functionality. If the critical region is reasonably faster than the bytecode version, there is probably still work to clean up the module to make it fail-safe.

‖放下 2024-08-29 01:22:37

在性能方面,HiPE 在模块内进行优化,而不是模块间调用。这可以产生非常好的加速(x4..x10 似乎是普遍吹捧的数字),但是正如其他人回答的那样,如果您的代码花费大量时间等待外部事件,则加速将可以忽略不计。

需要注意的是,HiPE 显然不支持某些渐进式语言功能,例如参数化模块。这意味着一些最近的应用程序(例如 MochiWeb)将根本无法运行。考虑到这一点。

Performance-wise, HiPE optimizes within modules - not inter-module calls. This can yield very good speedups (x4..x10 appear to be commonly touted numbers), however as others have replied, if your code spends a lot of time waiting for external events the speedup will be negligible.

Something to watch out for is that HiPE apparently does NOT support some progressive language features, such as Parameterized Modules. This means that some recent applications (such as MochiWeb) will not be runnable at all. Take this into account.

茶底世界 2024-08-29 01:22:37

在相关说明中,您可能会发现本文很有用:

user.it.uu .se/~kostis/Papers/erlang03.pdf

除了描述使用 HiPE 产生的限制之外,它还进行了一些(非常基本的)速度比较。

我发现最值得注意的两件事是:

  • 旧的 HiPE 代码在重新加载时不会消失,而是永远存在。因此,如果您处于非常频繁地重新加载代码的环境中,则会出现少量内存泄漏。通常并不是真正的问题,但如果您的节点没有良好的“退出策略”,则值得考虑(这允许您无缝地将节点从集群中取出并时不时地用新的节点替换它们——这也是无价的)当您想要升级到较新的 BEAM-VM 版本时。)
  • 在本机代码和解释代码之间切换时会产生一些开销,因此您会尽可能避免这种情况(通过编译与同一编译器频繁交互的所有模块)

On a related note, you might find this paper useful:

user.it.uu.se/~kostis/Papers/erlang03.pdf

Amongst describing the limitations that arise from using HiPE, it also has some (very basic) speed comparisations.

The two things I've found most notable:

  • old HiPE code, when reloaded, does not go away, but hangs around forever. So, a small memory leak, if you are in an environment where you reload code very frequently. Usually not really a problem, but worth considering if you do not have a good "exit-strategy" for your nodes (which allows you to seamlessly take nodes out of your cluster and replace them by fresh ones from time to time--also invaluable to have when you want to upgrade to a newer BEAM-VM version.)
  • There is some overhead when switching between native and interpreted code, so you would try to avoid that when possible (by compiling all modules that interact frequently with the same compiler)
远山浅 2024-08-29 01:22:37

原生应该更快。我认为速度有多快并没有一个恒定的因素;根据机器/架构等的不同,它肯定是不同的。

Native should be faster. I don't think theres a constant factor how much faster it is; It is surely different based on machine/architecture and so on.

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