News for hackers. Stuff that matters.
Re:Iris: Fast back-end web framework for Go by oneloop on Tuesday June 21, 2016 @07:53AM (#11945014)
Ok, so why is Python so slow (comparatively)? I had understood that must of the speed-critical tasks in python were done by wrappers of lower-level C code. Example: numpy. Is this not correct?
Re:Iris: Fast back-end web framework for Go by insertnickname on Tuesday June 21, 2016 @09:15AM (#11945341)
You can indeed do that, and there are other ways to speed up Python (PyPy, Cython, or even just writing more efficient Python code). However, the problem is that you now have to write C.

A lot of the slowness in Python probably comes from the many memory allocations all over the place. Go gives you a lot of control over allocations even though it is a garbage collected language.

These slides posted by another commenter has some good points about why Python is so slow: https://speakerdeck.com/alex/why-python-ruby-and-javascript-...

Interestingly, there was actually a talk at PyCon US 2016 about using Go's http server in Python via C. https://www.youtube.com/watch?v=CkDwb5koRTc

Re:Iris: Fast back-end web framework for Go by TheHydroImpulse on Tuesday June 21, 2016 @08:53AM (#11945248)
The reason it's slow is because python interprets it's input. It essentially introduces major indirection for instructions to be executed.

So for '1 + 1', you can't just output some fast x86 instruction and inline it. You'll usually need to jump to where the python vm will do 'a + b' in C. You're having to do a bunch of redundant work at a higher level to emulate the CPU (sorta).

That's why you have JIT compilers that will read '1 + 1' and compile the appropriate machine code, store that in an executable memory region and jump to it. First time might be slow, but after that it's pretty fast. Because you need to jump to the dynamically generated code, you usually compile whole functions at a time.

This topic is super complicated but also super interested but I tried to simplify it a bit here.

Re:Iris: Fast back-end web framework for Go by SEJeff on Tuesday June 21, 2016 @10:07AM (#11945674)
FWIW: There is a new set of async / await bits in CPython 3.5 that are allowing some really interesting new performance profiles.

http://magic.io/blog/uvloop-blazing-fast-python-networking/

This is almost exactly on par with golang's net/http for a simple echo server, yet it is written in python.