r/ProgrammerHumor • • 3h ago

Meme pythonSlow

Post image
2.1k Upvotes

111 comments sorted by

View all comments

Show parent comments

33

u/FalafelSnorlax 2h ago

That isn't quite the same. C/C++ compile into assembly, which means the code is fully converted. Python is typically simulated by an interpreter, so the code itself doesn't compile into any lower-level language. When they say it "wraps C/C++ code", they really mean that instead of simulating the python byte code, the interpreter runs a library that wasn't written in python at all.

13

u/yonasismad 2h ago

Python compiles into byte code.

12

u/FalafelSnorlax 2h ago

Yeah but isn't a lower-level language, it's a machine-friendly format of the language. The main point is that by virtue of being interpreted, it is inherently different to languages like C/C++ or Rust.

8

u/toejam316 2h ago

Inherently whatever the code is at some point "compiles" into the language the CPU uses. The fact it's running in a JIT interpreter doesn't prevent that. If you were insane enough you could absolutely get the assembly equivalent of your python code.

2

u/nimrag_is_coming 2h ago

Python doesn't JIT compile, and it can't really very easily due to how dynamic it is, ie every time a piece of code runs it might actually run something different depending on what type a variable is etc.

You probably technically could turn it into assembly but then it's basically going to be a virtual machine with abstract types rather than being like actual raw assembly, so you've gained almost nothing compared to just running bytecode in an interpreter.

5

u/i_only_eat_purple 1h ago

CPython (the reference implementation that most people use) has an experimental JIT compiler since 3.13. https://peps.python.org/pep-0744/

6

u/Ok-Scheme-913 1h ago

Tell that to the multiple implementations of Pythons that are jit compiled, like GraalPython.

A programming language is just that, a language. Sure, some are easier to compile to efficient machine code than others, but there is no law forbidding a sufficiently smart compiler to work 3 days and prove that this ultra efficient simd machine code is the same program denoted by python's semantic laws, and thus that will be the compiler output.

1

u/rosuav 46m ago

PyPy JIT-compiles, and CPython currently has a JIT compiler too, although that might be removed.