是否有Ruby / Python特性阻碍了V8引擎的优化实现(例如内联缓存)?
Python是由谷歌的人共同开发的,所以它不应该被软件专利所阻止。
或者这是谷歌在V8项目中投入的资源问题。
是否有Ruby / Python特性阻碍了V8引擎的优化实现(例如内联缓存)?
Python是由谷歌的人共同开发的,所以它不应该被软件专利所阻止。
或者这是谷歌在V8项目中投入的资源问题。
当前回答
There's a lot more impetus to highly optimize JavaScript interpretors which is why we see so many resources being put into them between Mozilla, Google, and Microsoft. JavaScript has to be downloaded, parsed, compiled, and run in real time while a (usually impatient) human being is waiting for it, it has to run WHILE a person is interacting with it, and it's doing this in an uncontrolled client-end environment that could be a computer, a phone, or a toaster. It HAS to be efficient in order to run under these conditions effectively.
Python和Ruby运行在一个由开发人员/部署人员控制的环境中。一个健壮的服务器或桌面系统,限制因素通常是内存或磁盘I/O,而不是执行时间。或者可以利用缓存等非引擎优化。对于这些语言,关注语言和库特性集而不是速度优化可能更有意义。
这样做的附带好处是,我们拥有两个出色的高性能开源JavaScript引擎,它们可以并且正在被重新用于各种应用程序,例如Node.js。
其他回答
Misleading question. V8 is a JIT (a just in time compiler) implementation of JavaScript and in its most popular non-browser implementation Node.js it is constructed around an event loop. CPython is not a JIT & not evented. But these exist in Python most commonly in the PyPy project - a CPython 2.7 (and soon to be 3.0+) compatible JIT. And there are loads of evented server libraries like Tornado for example. Real world tests exist between PyPy running Tornado vs Node.js and the performance differences are slight.
性能似乎并不是核心Python开发人员的主要关注点,他们似乎觉得“足够快”就足够好了,而且帮助程序员提高工作效率的功能比帮助计算机更快地运行代码的功能更重要。
然而,确实有一个谷歌项目unladen-swallow(现在已被放弃),目的是生产一个与标准解释器兼容的更快的Python解释器。PyPy是另一个旨在生成更快Python的项目。还有Psyco,它是PyPy的前身,它可以在不更改整个解释器的情况下为许多Python脚本提供性能提升,还有Cython,它允许您使用非常类似于Python语法的东西为Python编写高性能C库。
正如其他人所提到的,Python有一个PyPy形式的高性能JIT编译器。
Making meaningful benchmarks is always subtle, but I happen to have a simple benchmark of K-means written in different languages - you can find it here. One of the constraints was that the various languages should all implement the same algorithm and should strive to be simple and idiomatic (as opposed to optimized for speed). I have written all the implementations, so I know I have not cheated, although I cannot claim for all languages that what I have written is idiomatic (I only have a passing knowledge of some of those).
我没有任何明确的结论,但PyPy是我得到的最快的实现之一,比Node好得多。相反,CPython位于排名最慢的一端。
这很大程度上与社区有关。Python和Ruby在很大程度上没有企业支持。没有人会因为全职从事Python和Ruby而获得报酬(特别是他们不会因为一直从事CPython或MRI而获得报酬)。另一方面,V8得到了世界上最强大的IT公司的支持。
此外,V8可以更快,因为对V8的人来说唯一重要的事情是解释器——他们没有标准库可以工作,不需要考虑语言设计。他们只编写解释器。就是这样。
这与知识产权法无关。Python也不是由谷歌的人共同开发的(它的创建者和其他一些提交者一起在那里工作,但他们没有为Python工作而获得报酬)。
Python速度的另一个障碍是Python 3。它的采用似乎是语言开发人员最关心的问题——以至于他们冻结了新语言特性的开发,直到其他实现赶上来。
关于技术细节,我不太了解Ruby,但是Python有很多地方可以使用优化(Unladen Swallow,一个谷歌项目,在失败之前就开始实现这些)。这是他们计划的一些优化。如果CPython实现了像PyPy一样的JIT,我可以看到Python在未来达到V8的速度,但这在未来几年似乎不太可能(现在的重点是采用Python 3,而不是JIT)。
许多人还认为Ruby和Python可以从移除它们各自的全局解释器锁中获益良多。
You also have to understand that Python and Ruby are both much heavier languages than JS -- they provide far more in the way of standard library, language features, and structure. The class system of object-orientation alone adds a great deal of weight (in a good way, I think). I almost think of Javascript as a language designed to be embedded, like Lua (and in many ways, they are similar). Ruby and Python have a much richer set of features, and that expressiveness is usually going to come at the cost of speed.
因为JavaScript实现不需要关心其绑定的向后兼容性。
Until recently the only users of the JavaScript implementations have been web browsers. Due to security requirements, only the web browser vendors had the privilege to extend the functionality by writing bindings to the runtimes. Thus there was no need keep the C API of the bindings backwards compatible, it was permissible to request the web browser developers update their source code as the JavaScript runtimes evolved; they were working together anyways. Even V8, which was a latecomer to the game, and also lead by a very very experienced developer, have changed the API as it became better.
OTOH Ruby(主要)用于服务器端。许多流行的ruby扩展被编写为C绑定(考虑RDBMS驱动程序)。换句话说,如果不保持兼容性,Ruby就永远不会成功。
今天,这种差异在某种程度上仍然存在。使用node.js的开发人员抱怨很难保持他们的本机扩展向后兼容,因为V8会随着时间改变API(这也是node.js被分叉的原因之一)。IIRC ruby在这方面仍然采取更为保守的方法。