4 ms·
> It's run, line-by-line through an interpreter, and turned into byte-code, which is executed by the VM. Just a small technical correction: you can pre-complie
by segfaultbuserr 4y ago
> It's run, line-by-line through an interpreter, and turned into byte-code, which is executed by the VM.
Just a small technical correction: you can pre-complie to .py source files to .pyc bytecode files without waiting for the interpreter to do it line by line, many distro package managers already perform this step automatically when a package is installed. Though you're right in the sense that it doesn't really improve performance, CPython itself is the slowest part, not bytecode generation.
> There's no compilation, and in CPython, very little optimisation.
+1. This was actually a deliberate design choice [0]. Guido van Rossum himself said, "Python is about having the simplest, dumbest compiler imaginable." CPython was designed for ease of learning and use, it was never designed to be a high-performance language. Pure Python code (without C extensions like NumPy) can never be good at number-crunching tasks.
[0] https://nullprogram.com/blog/2019/02/24/ https://nullprogram.com/blog/2019/02/24/
- falcolas 4y agoThere are still some basic optimizations the Python compiler makes. It has, for example, a keyhole optimizer, and some built in optimizations around integer objects to name two. It’s nothing too fancy, but it still does the basics.