36

TIL there's a Python Interpreter written in Python (PyPy)

My head hurts

Comments
  • 4
    That doesn't even make any sense. You'd just slow down the runtime by basically evaluating everything twice.
  • 0
    @nitwhiz Exactly and it's beautiful
  • 0
    @Frederick one for python?
  • 3
    @nitwhiz They boast it's faster because it's a JIT interpreter.

    And to be fair as soon as the interpreter is interpreted it doesn't need to be interpreted again
  • 1
    @AlgoRythm what. Still you'd have to interpret the statement "alloc memory" and tell the engine to do so. With pypy it's intetpreting "alloc memory", issues "alloc memory", which then is interpreted by the engine. Or not?
  • 1
    @nitwhiz While there are more steps involved, it isn't equivalent to interpreting something twice as if reading the same file twice
  • 0
    @AlgoRythm the thing that makes me wonder.. if there is such a weird workaround to gain performance, wouldn't be implemented already?
  • 0
    @Frederick Yeah :D is PyPy open source?
  • 1
    @nitwhiz Actual production CPython moves somewhat slowly. Read up on their GIT (different from JIT) issue :)

    Implementing JIT would require large portions of the codebase to be re-written
  • 1
    @Charon92 Ah, FUK me
  • 0
    @nitwhiz it is actually faster than CPy but consumes much more memory from what I've heard.
  • 4
    For clarification PyPy isn't written in normal Python, but RPython.
    It is a special language by the PyPy team to create JIT compiled interpreters for any language. This is the reason PyPy may actually be faster for Python code (overall faster, but depends on the code).
    The downside is a "warmup phase" (to determine which code can be practically compiled natively?), higher memory usage (at least on my systems) and slow interaction with C modules (as long as not accessed by CFFI).

    There also exists a PyPy variant without GIL for x64-Linux.
  • 1
    You know that the python interpreter is written in python right?
  • 0
    @ewpratten Most languages end up doing that. Java, for example, is largely implemented in Java. I'm sure you know more than me about c compilers but I'm assuming they are, in large part, written in c. I'm sure they Python interpreter is written in Python. It's all just one recursive clusterfuck.

    Lua is still pure C though!
  • 0
    Well, that's just bootstrapping to be honest.
  • 0
    It's pythons all the way down.
  • 0
    @AlgoRythm I don't know much about compilers and interpreters but isn't it the point that you write a interpreter in a compiled language? If you're interpreter is written in Python what does interpret the interpreter?
  • 0
    The c# compiler is written in c#.
  • 0
    I want less Python not more
Add Comment