Why shouldn't I use PyPy over CPython if PyPy is 6.3 times faster?

前端 未结 12 1088
暖寄归人
暖寄归人 2020-12-02 03:12

I\'ve been hearing a lot about the PyPy project. They claim it is 6.3 times faster than the CPython interpreter on their site.

Whenever we talk about dynamic languag

相关标签:
12条回答
  • 2020-12-02 04:01

    The second question is easier to answer: you basically can use PyPy as a drop-in replacement if all your code is pure Python. However, many widely used libraries (including some of the standard library) are written in C and compiled as Python extensions. Some of these can be made to work with PyPy, some can't. PyPy provides the same "forward-facing" tool as Python --- that is, it is Python --- but its innards are different, so tools that interface with those innards won't work.

    As for the first question, I imagine it is sort of a Catch-22 with the first: PyPy has been evolving rapidly in an effort to improve speed and enhance interoperability with other code. This has made it more experimental than official.

    I think it's possible that if PyPy gets into a stable state, it may start getting more widely used. I also think it would be great for Python to move away from its C underpinnings. But it won't happen for a while. PyPy hasn't yet reached the critical mass where it is almost useful enough on its own to do everything you'd want, which would motivate people to fill in the gaps.

    0 讨论(0)
  • 2020-12-02 04:03

    Because pypy is not 100% compatible, takes 8 gigs of ram to compile, is a moving target, and highly experimental, where cpython is stable, the default target for module builders for 2 decades (including c extensions that don't work on pypy), and already widely deployed.

    Pypy will likely never be the reference implementation, but it is a good tool to have.

    0 讨论(0)
  • 2020-12-02 04:03

    CPython has reference counting and garbage collection, PyPy has garbage collection only.

    So objects tend to be deleted earlier and __del__ is called in a more predictable way in CPython. Some software relies on this behavior, thus they are not ready for migrating to PyPy.

    Some other software works with both, but uses less memory with CPython, because unused objects are freed earlier. (I don't have any measurements to indicate how significant this is and what other implementation details affect the memory use.)

    0 讨论(0)
  • 2020-12-02 04:03

    For a lot of projects, there is actually 0% difference between the different pythons in terms of speed. That is those that are dominated by engineering time and where all pythons have the same amount of library support.

    0 讨论(0)
  • 2020-12-02 04:08

    NOTE: PyPy is more mature and better supported now than it was in 2013, when this question was asked. Avoid drawing conclusions from out-of-date information.


    1. PyPy, as others have been quick to mention, has tenuous support for C extensions. It has support, but typically at slower-than-Python speeds and it's iffy at best. Hence a lot of modules simply require CPython. PyPy doesn't support numpy PyPy now supports numpy. Some extensions are still not supported (Pandas, SciPy, etc.), take a look at the list of supported packages before making the change.
    2. Python 3 support is experimental at the moment. has just reached stable! As of 20th June 2014, PyPy3 2.3.1 - Fulcrum is out!
    3. PyPy sometimes isn't actually faster for "scripts", which a lot of people use Python for. These are the short-running programs that do something simple and small. Because PyPy is a JIT compiler its main advantages come from long run times and simple types (such as numbers). Frankly, PyPy's pre-JIT speeds are pretty bad compared to CPython.
    4. Inertia. Moving to PyPy often requires retooling, which for some people and organizations is simply too much work.

    Those are the main reasons that affect me, I'd say.

    0 讨论(0)
  • 2020-12-02 04:09

    Supported Python Versions

    To cite the Zen of Python:

    Readability counts.

    For example, Python 3.7 introduced dataclasses and Python 3.8 introduced fstring =.

    There might be other features in Python 3.7 and Python 3.8 which are more important to you. The point is that PyPy does not support Python 3.7 or Python 3.8 at the moment.

    Shameless self-advertisement: Killer Features by Python version - if you want to know more things you miss by using older Python versions

    0 讨论(0)
提交回复
热议问题