Why is Python slow
Kevin Modzelewski kmod@dropbox.com
It’s not what many people think
Getting rid of “interpreter overhead” provides very small wins.
Also one of the easiest things for the user to do themselves.
Try it yourself
Compile with Cython without type annotations
Try it yourself
��
4.5 ns/bytecode 9.0 ns/bytecode
sqlalchemy_smalltest2_10x.py: 111 ns/bytecode
def f():
a = 1
for i in range(10000000):
a; a; a; a; a; a; a; a
a; a; a; a; a; a; a; a
a; a; a; a; a; a; a; a
f()
def f():
i = 10000000
t = 0
while i:
t += i
i -= 1
f()
What is it then?
Lots of expensive features
Dynamic overhead of the runtime
“Speed bumps”
Dynamic runtime
�
The C runtime is 6x slower than an equivalent javascript loop!
import itertools
sum(itertools.repeat(1.0, 100000000))
Conclusion
Lots of time has been invested into interpreter overhead
Let’s shift the effort to other areas