TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

If PyPy is 6.3 times faster than CPython, why not just use it?

140 点作者 neokya超过 11 年前

9 条评论

seiji超过 11 年前
[actual real code story example]<p>I wrote two approaches to the same problem.<p>The first approach uses simple python data structures and greedy evaluation. It runs under CPython in 0.15 seconds. Running under pypy takes 1.2 seconds. pypy is 8x slower.<p>The second approach (using the same data) builds a big graph and visits nodes v^3 times. Running under CPython takes 4.5 seconds. Running under pypy takes 1.6 seconds. pypy is almost 3x faster.<p>So... that&#x27;s why. &quot;It depends.&quot; But—it&#x27;s great we have two implementations of one language where one jits repetitive operations and the other evaluates straight-through code faster.
评论 #6428850 未加载
评论 #6427691 未加载
haberman超过 11 年前
&gt; Because PyPy is a JIT compiler it&#x27;s main advantages come from long run times and simple types (such as numbers).<p>It is not <i>inherent</i> to JIT compilers that they need long running times or simple types to show benefit. LuaJIT demonstrates this. Consider this simple program that runs in under a second and operates only on strings:<p><pre><code> vals = {&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;, &quot;g&quot;, &quot;h&quot;, &quot;i&quot;, &quot;j&quot;, &quot;k&quot;, &quot;l&quot;, &quot;m&quot;, &quot;n&quot;, &quot;o&quot;} for _, v in ipairs(vals) do for _, w in ipairs(vals) do for _, x in ipairs(vals) do for _, y in ipairs(vals) do for _, z in ipairs(vals) do if v .. w .. x .. y .. z == &quot;abcde&quot; then print(&quot;.&quot;) end end end end end end $ lua -v Lua 5.2.1 Copyright (C) 1994-2012 Lua.org, PUC-Rio $ time lua ..&#x2F;test.lua . real 0m0.606s user 0m0.599s sys 0m0.004s $ luajit -v LuaJIT 2.0.2 -- Copyright (C) 2005-2013 Mike Pall. http:&#x2F;&#x2F;luajit.org&#x2F; $ time .&#x2F;luajit ..&#x2F;test.lua . real 0m0.239s user 0m0.231s sys 0m0.003s </code></pre> LuaJIT is over twice the speed of the (already fast) Lua interpreter here for a program that runs in under a second.<p>People shouldn&#x27;t take the heavyweight architectures of the JVM, PyPy, etc. as evidence that JITs are <i>inherently</i> heavy. It&#x27;s just not true. JITs can be lightweight and fast even for short-running programs.<p>EDIT: it occurred to me that this might not be a great example because LuaJIT isn&#x27;t actually generating assembly here and is probably winning just because its platform-specific interpreter is faster. <i>However</i> it is still the case that it is instrumenting the code&#x27;s execution and paying the execution costs associated with attempting to find traces to compile. So even with these JIT-compiler overheads it is still beating the plain interpreter which is only interpreting.
评论 #6427684 未加载
评论 #6428359 未加载
kbuck超过 11 年前
I actually experimented a while ago by running a long-running Twisted-based daemon on top of PyPy to see if I could squeeze more speed out. PyPy did indeed vastly increase the speed versus the plain Python version, but once I discovered that Twisted was using select&#x2F;poll by default and switched it to epoll, my performance issues with the original CPython version were gone (and PyPy couldn&#x27;t use Twisted&#x27;s epoll at the time).<p>Another major issue was that running the daemon under PyPy used about 5 times the memory that the CPython version did. This was a really old version of PyPy, though, so they have probably fixed some of this memory greediness.
评论 #6427909 未加载
RamiK超过 11 年前
Because CPython came first.<p>Because Python isn&#x27;t about performance.<p>Because it&#x27;s not really 6.3 times faster for most(any?) use cases.<p>Because VMs are misunderstood as superfluous abstractions where a good interpreter should be instead.<p>Because VMs are understood as superfluous abstractions where a good OS should be instead.<p>...<p>And most of all, because better hardware costs less then the extra man hours involved the transition.
评论 #6429169 未加载
dmk23超过 11 年前
PyPy has LOTS of problems with 3rd party libraries. If you want to deploy it in production you&#x27;ll have to check that each one of them does exactly what you need it to and oftentimes you are surprised how things are broken.<p>We are using PyPy for some of our services (where it is doing about x3 faster than CPython), while for some others (Django UI - at least the way we are using it) we found that PyPy is actually slower, so we are sticking with CPython.<p>Unfortunately PyPy team has not even made it their priority to test PyPy with Django. It is one thing to have a cookie-cutter test suite that measures simple use cases and it is entirely different matter to test how well it can run the whole stack of apps on top of it.
评论 #6429667 未加载
Elv13超过 11 年前
I would like to point out that while (c)python reliance on C seem to be the problem here, it is not inherent to general use of C either. Again, Lua vs. LuaJit prove that a Jit implementation can be a drop in to an other (non Jit) one.<p>On Gentoo, I tend to force applications to link against LuaJit and it works just fine.<p>Message written in LuaKit using AwesomeWM and my alt+tag show VLC, Wireshark and MySql Workbench running, all on LuaJit to some level of success (most are flawless). All of those applications doesn&#x27;t (AFIAK) officially support LuaJit.
评论 #6428397 未加载
tomrod超过 11 年前
It&#x27;s a great question. I&#x27;d say for myself I&#x27;ve been hesitant to use CPython or PyPy simply because their documentation seems focused on the extremely technical, rather than a person just trying it out for the first time.<p>I know Python, and I know C. But I&#x27;m worried ending up down rabbit holes in PyPy and competitors. I&#x27;ve not been able to find a really solid tutorial or parse the docs very well.<p>Perhaps it&#x27;s just me, though. That&#x27;s always possible. I just see a large barrier to adoption.
评论 #6428325 未加载
robert-zaremba超过 11 年前
I&#x27;m successfully using PyPy in production. It&#x27;s about data processing. The most important dependencies: redis driver, beautiful soup.<p><pre><code> PyPy cPython jobs&#x2F;sec ~60 ~8 mem usage 1.5G 2G </code></pre> When using lxml on cPython, the jobs&#x2F;sec increased to 10 (on that time lxml wasn&#x27;t supported by PyPy, now it is). I really encourage to give a try to PyPy.
z3phyr超过 11 年前
Will CPython always remain the reference implementation?