Python for Network Engineers

Why Is Python Slow?

by: George El., January 2021, Reading time: 2 minutes

This post is largely based on this video which I highly highly recommend from Pycon 2020. If you don’t want to watch the whole video, here is the most important points.

Python is hundred times slower than compiled languages like C and GO and this is expected, since python is interpreted. However the surprise is that Python is also hundred times slower than other interpreted languages like javascript and node. Actually js and node use the same V8 engine.

ftp control

So why is this happening? The answer is that Python uses an Ahead of Time Compiler (AOT) while Javascript uses Just In Time Compiler (JIT). JIT compilers look at the code and they do on the fly optimizations. So lets do a JIT for Python, right? Wrong. In Python half of the libraries are precompiled C binaries, so you cannot use a JIT.

Nevertheless Python is a very popular language. I think the main reason for this is the libraries. It has a wealth of libraries for every field, including Networking, ML etc. However, if you would like to write an app that can scale to millions of users, I think you should use something like GO. In GO one server can handle 1 million websockets. There is a video on youtube about that. It is not a accident that the GO language is very popular in China, since China has almost a billion of people, and the apps need to be scalable.

comments powered by Disqus