Can we expect a speed gain by transitioning from PHP to Hack on HHVM?

我们能指望从PHP过渡到攻击HHVM的速度提高吗?

I'm thinking of the strongly typed parameters / return types, in particular scalars, does that allow HHVM to do a better job at compiling the code to native code, or is the speed gain insignificant as compared to using classic PHP and its mixed types?

我在考虑强类型参数/返回类型,特别是标量,这是否允许HHVM更好地将代码编译为本地代码,或者与使用传统的PHP及其混合类型相比,速度的提高是否微不足道?

1 个解决方案

#1


56

I answered this on Reddit a few months back. I've copied my answer below, since the state of the world hasn't changed much since then. But keep in mind that HHVM is still evolving, pretty quickly actually, and so this could easily be out of date in a month or two more.

几个月前,我在Reddit上回答了这个问题。我在下面复制了我的答案,因为世界的现状从那时起并没有太大的变化。但是请记住,HHVM仍然在快速地发展,因此在一两个月后,这种方法很容易就会过时。

I work on the Hack team at Facebook. The answer to this question is somewhat subtle.

我在Facebook的黑客团队工作。这个问题的答案有点微妙。

Moving your PHP code from PHP5 to HHVM is likely to result in a significant speedup, as others have said. How significant depends on a ton of factors. If you're already IO bound, you may not see much at all; if you are closer to CPU bound, speedups of up to something like 5x have been reported, though you are likely to get something somewhere inbetween. You should go and try it on your own code, with a real workload -- HHVM has a bunch of factors, notably a larger startup time, that make it not do so well on microbenchmarks, but on real workloads it should outperform PHP5. For maximum benefit, refactoring your code to get things out of toplevel and into functions/classes will help a ton (we can't JIT code at toplevel), as will setting up repo authoritative mode.

将PHP代码从PHP5移动到HHVM可能会导致显著的加速,正如其他人所说的那样。重要程度取决于很多因素。如果你已经有了IO限制,你可能看不到太多;如果您更接近于CPU,那么就会有大约5x的速度被报告,尽管您很可能会在两者之间找到一些东西。您应该使用真正的工作负载,在自己的代码上尝试它——HHVM有很多因素,尤其是更长的启动时间,这使得它在微基准上做得不太好,但在实际工作负载上,它应该优于PHP5。为了获得最大的好处,重构代码以使代码脱离顶层并进入函数/类将会有很大的帮助(我们不能在顶层JIT代码),就像建立repo权威模式一样。

But that's just plain PHP on HHVM, not Hack on HHVM. What speedup do you get from then converting your code to Hack? It depends on how you do the conversion, but the answer is, at least right now, "not very much". If you just go stick <?hh at the top of every file, instead of <?php, and fix any incompatibilities that come up when you run the typechecker, then your code will very likely perform the same as before. Hack and PHP code have the same runtime representation, so you haven't really changed much.

但这只是在HHVM上的普通PHP,而不是在HHVM上。将代码转换为Hack可以得到什么加速?这取决于你如何转换,但答案是,至少现在,“不是很多”。如果你坚持

If you do that, though, then you aren't taking full advantage of Hack! If you go in and start adding type annotations, you can build up more and more information for HHVM to use at runtime. This process is what can speed up your code -- HHVM can generate type-specialized (i.e., faster) code in a lot of circumstances where before it might have not been able to infer the type. Don't expect a huge speedup here either -- this is largely theoretical right now, and there are lots of places we can be taking better advantage of the type information to generate faster code. (We don't do much with return types at runtime right now, for example.) But this is the part that might help, and might help more as HHVM gets smarter.

如果你这么做了,那么你就没有充分利用黑客!如果您加入并开始添加类型注释,您可以为HHVM构建越来越多的信息,以便在运行时使用。这个过程可以加速您的代码——HHVM可以生成类型专门化的(例如。在许多情况下,在许多情况下,在此之前它可能无法推断类型。这里也不要期望会有巨大的加速——这在很大程度上是理论性的,而且有很多地方我们可以更好地利用类型信息来生成更快的代码。(例如,我们现在在运行时不太使用返回类型。)但这一部分可能会有所帮助,而且随着HHVM变得越来越聪明,可能会帮助更多。

But of course, keep in mind that execution speed wasn't the point of Hack -- it was about developer efficiency. Any performance gain is probably not going to be worth the effort going from PHP on HHVM to Hack on HHVM. The gain in developer productivity, though, probably is.

但是,当然,请记住,执行速度并不是问题的关键——它与开发人员的效率有关。从PHP到HHVM,再到攻击HHVM,任何性能上的提升都可能不值得。不过,开发人员生产率的提高可能是这样的。

So does moving from PHP5 to HHVM speed up your code? Very likely. Does doing a quick conversion to Hack speed it up? No. Does adding more type annotations speed it up? Maybe a little, maybe more in the future, but that's not really the point.

那么从PHP5迁移到HHVM是否会加快代码的速度呢?很有可能。做一个快速的转换来加快它吗?不。添加更多的类型注释是否加快了速度?也许将来会有更多,但这并不是重点。

更多相关文章

  1. 指导我优化我的PHP代码,用数组中的空数据填充缺失值
  2. 如何捕获PHP类型暗示的“可捕获的致命错误”?
  3. [php]在PHP中读取和写入WORD文档的代码
  4. php评论回复无限极嵌套如何实现?已写基本代码,期待高手解惑
  5. advertising.php源代码分析
  6. thinkphp友情链接代码
  7. 如何在php中找到更轻或更暗版本的十六进制代码的十六进制代码
  8. PHP 网站保存快捷方式的实现代码
  9. 正则表达式匹配wordpress类似的短代码,用于自闭和封闭。

随机推荐

  1. Linux CentOS6环境下MySQL5.1升级至MySQL
  2. Linux 开/关 ICMP 回应(防止被ping)
  3. 《Unix & Linux 大学教程》 - 第十九章(一
  4. linux vim下如何让类似txt的文本,呈现出某
  5. 我从网上下载了RedHat Linux 9.03,是三个
  6. 红帽Linux6虚拟机克隆后操作
  7. Linux命令基础-rmdir和rm命令
  8. 如何静态构建qt5
  9. 在linux上安装oracle11G必须在图形界面才
  10. Linux Shell编程(15)——操作字符串