News for hackers. Stuff that matters.
Re:Why Python Is Slow: Looking Under the Hood (2014) by weberc2 on Thursday July 07, 2016 @04:27PM (#12051882)
There are faster Python implementations, namely Pypy. I think one of the reasons Pypy isn't more popular is because it's C interoperability story is weaker than the reference Python implementation (CPython--not to be confused with Cython), or at least it's not compatible with many important C-based Python libraries (e.g., Pandas).
Re:Why Python Is Slow: Looking Under the Hood (2014) by Animats on Thursday July 07, 2016 @05:29PM (#12052200)
"I think one of the reasons Pypy isn't more popular is because its C interoperability story is weaker than the reference Python implementation"

The CPython crowd apparently made some change between CPython 3.4 and CPython 3.5 which changed how Windows DLLs are called. This broke Py2exe, which no longer works for the current release of CPython. [1]

CPython's approach to C extensions usually requires having the same Microsoft C compiler version used to build Python. This is now a problem for Python 2.7, because the Microsoft compiler version used to build it is no longer available. Microsoft recently changed their API for the C runtime, and CPython has been changed accordingly.

CPython's "C interoperability story" isn't really that good on Windows.

[1] http://stevedower.id.au/blog/building-for-python-3-5/

Re:Why Python Is Slow: Looking Under the Hood (2014) by ihnorton on Thursday July 07, 2016 @06:16PM (#12052427)
> This is now a problem for Python 2.7, because the Microsoft compiler version used to build it is no longer available.

There is a CMake build system for 2.7 that works great with VS2013-2015:

https://github.com/python-cmake-buildsystem/python-cmake-bui...

Re:Why Python Is Slow: Looking Under the Hood (2014) by cdavid on Thursday July 07, 2016 @06:30PM (#12052496)
The issue w/ MSVC is not that specific to CPython. It is generally quite hard to write libraries which use multiple C runtimes (Windows or not -- it just happens to be much more common on Windows than on Unix). I would be actually very surprised if that problem did not exist with any other language that distribute binaries.

Note that the problem you mentioned w/ python 2.7 is gone: MS has made a .msi available free of charge to build C extensions for 2.7, indefinitely (thanks to Steve Dower): https://www.microsoft.com/en-gb/download/details.aspx?id=442...

Re:Why Python Is Slow: Looking Under the Hood (2014) by int_19h on Thursday July 07, 2016 @06:02PM (#12052353)
It's good enough for practical purposes - sure, you have to build a separate version of your package for every different version of VC++ that is used by your supported versions of Python, but we're still talking about 3-4 binaries top.

When that is not enough, you can still recompile manually if need be, so long as source for the module is available (which it is in most cases).

On the other hand, native modules are such a big part of the Python ecosystem, that not supporting the API and ABI at all confines any alternative implementations to a very small niche.

Re:Why Python Is Slow: Looking Under the Hood (2014) by enos on Thursday July 07, 2016 @08:05PM (#12052860)
This is true on other OSes as well. C extensions are assumed to be compiled with the same compiler as Python itself. If you use distutils it will also use the same flags.

This is less problematic on other OSes where GCC dominates and clang is compatible, but it can bite on HPC systems that use PGI compilers.

Re:Why Python Is Slow: Looking Under the Hood (2014) by adrianratnapala on Thursday July 07, 2016 @05:02PM (#12052054)
The C-compatbility story works both ways. I usually roll my eyes when people talk about making dynamic lanuages fast -- what's the point? In those cases where speed matters - use static language. As a result there is little incentive to use something like PyPy (although PyPy does have other nice features in addition to raw speed).

But on the web there is a point. Unless you can use HTML alone, you have to use JavaScript -- and you can't just plug in a module that you wrote in C.

Re:Why Python Is Slow: Looking Under the Hood (2014) by static_noise on Thursday July 07, 2016 @05:27PM (#12052188)
It's about managing your resources. You can simply buy the fastest processor for cheap money. You can buy systems with many cores or even build a cluster for considerable money.

But you can not buy time.

Developing python applications in many cases is much quicker than developing comparable applications in C++, C or Assembler. Therefore it makes a lot of sense for many companies to choose tools with quick development time to get the product running and care for performance later.

Since there may be so much code be written in python, it cannot simply be converted into a faster language since most critical parts are already accelerated using the proper libraries provided by the language ecosystem. Porting a complex application to another language in many cases is a really hard problem and might even not be possible to be done in smaller steps.

Therefore we need every bit of performance we can squeeze out of python. The whole world will gain from that. If we manage great strides like JavaScript it would be glorious!

Re:Why Python Is Slow: Looking Under the Hood (2014) by weberc2 on Thursday July 07, 2016 @06:07PM (#12052376)
Assembler isn't statically typed, and C and C++ are particularly bad examples of productive static languages. Go is a much better example, but it disproves your thesis that dynamic languages are more productive than static languages (I have 6 years of Python experience and 3 years of Go experience, and Go is at least as easy as Python for small, single-threaded code bases and it scales much better with team size, code volume, and thread count).
Re:Why Python Is Slow: Looking Under the Hood (2014) by BuckRogers on Friday July 08, 2016 @03:12AM (#12053998)
Yeah, but Go is 20-50% less productive, depending on who you ask. From my experience I'd say it's at least 25% less productive than Python. Not horrible but I think 25% is a minimum value and a quarter of your time adds up. I don't think it's worth the trade off once you consider every language has its warts, Go has its own problems.
Re:Why Python Is Slow: Looking Under the Hood (2014) by weberc2 on Friday July 08, 2016 @10:43AM (#12055885)
That's not been my experience, and I'm a Python developer by trade. Python simply doesn't scale well with code size, team size, performance requirements, etc.

Go's biggest problem is a lack of generics, which means that in some cases, you have to fall back to duck typing. So the worst case is no worse than Python's best case.

Re:Why Python Is Slow: Looking Under the Hood (2014) by BuckRogers on Saturday July 09, 2016 @02:45AM (#12060443)
My largest Go project has been 40KLOC, after which I felt that Python would've been at least 25% more productive.

The next-step isn't Go. It's Elixir. Or Rust if you need a systems language.

Re:Why Python Is Slow: Looking Under the Hood (2014) by cmdrfred on Thursday July 07, 2016 @05:37PM (#12052232)
Also soon enough (if we aren't there already), fast hardware will be so cheap that the speed of execution at least for end user applications will rarely be a factor. Sure that database application you wrote in C is measurably faster, but can a human being detect the difference? More and more the response will be no.
Re:Why Python Is Slow: Looking Under the Hood (2014) by weberc2 on Thursday July 07, 2016 @06:15PM (#12052415)
In the last 5 years, clock speeds have stagnated. Hardware innovation has revolved around increasing cores and improving power efficiency. Unfortunately, Python and most other dynamic languages are poorly suited to take advantage of parallelism, so your C database can only get faster, but your Python database will not.
Re:Why Python Is Slow: Looking Under the Hood (2014) by pcwalton on Thursday July 07, 2016 @08:14PM (#12052887)
Honestly, the vast majority of languages are bad at parallelism. Dynamic vs. static doesn't have much to do with it. Task-parallel multicore (like goroutines and Web Workers and the like give you) is only a small fraction of what it means to "take advantage of parallelism", and if you're only using that (as opposed to SIMD, GPUs, concurrent data structures, work-stealing, etc.) then you are likely to see disappointing speedups in practice.

This is especially true in the last 5 years, which contrary to your post has seen a shift away from multicore task-parallel hardware (core counts are not increasing) and toward data-parallel hardware (wider SIMD lanes, better on-board GPUs, APU architectures, etc.)

Re:Why Python Is Slow: Looking Under the Hood (2014) by weberc2 on Thursday July 07, 2016 @10:31PM (#12053290)
You're missing the point. There's "suboptimal parallelism", and then there's "no parallelism". Python and many other dynamic languages fall into the latter category.
Re:Why Python Is Slow: Looking Under the Hood (2014) by BuckRogers on Friday July 08, 2016 @03:16AM (#12054012)
I'd call Python optimal parallelism. I prefer the scaling by instance method of Node and Python over the old ways- writing multithreaded Java apps. People can knock themselves out writing stuff like that if they want to. But my purposes have been well-served scaling by spinning up instances per-core.

For me, explicit pthreading should never be done except with systems software. In which case you're going to be using a systems language like C, C++ or Rust anyway. Not the oddball middletier stuff that isn't high or low level like Go, Java and C#.

Re:Why Python Is Slow: Looking Under the Hood (2014) by weberc2 on Friday July 08, 2016 @11:23AM (#12056150)
Go's parallelism model is fundamentally different than the other languages you mentioned. Even if you never write any concurrent Go yourself, you could write single threaded routes and let the webserver handle the parallelism (this is more efficient than spinning up an OS thread per request). With Python, you also have to configure uwsgi or some such to deploy your application to each thread; with Go, the runtime handles this for you completely transparently--just run the binary and you're all set. Go isn't perfect, but using Python the way you are is just leaving money on the table.
Re:Why Python Is Slow: Looking Under the Hood (2014) by weberc2 on Friday July 08, 2016 @01:28PM (#12057202)
In response to @pcwalton:

> In the case of an I/O bound Web server, I don't think that Go is going to appreciably result in "leaving money on the table". Python releases the GIL on I/O, which is where your time is largely spent.

GIL doesn't matter, the OP said he was writing single threaded application. This means he's doing async (unlikely) or blocking the entire application process (not just the current request) on I/O.

> Linux is very fast at spawning threads. When you're doing I/O, it doesn't matter.

Not as fast as goroutines, and spawn speed isn't the only (or even the most interesting) measure of efficiency--you can run several orders of magnitude more goroutines on a Linux box than you can threads. Of course, none of this is relevant to this conversation, since the OP is talking about running a single-threaded Python process per core.

> Go's concurrency is not "fundamentally different" from any of the other languages. It's just an implementation of thread-per-connection in userspace. This is an implementation detail, and for a typical Web server I think it doesn't matter much.

You're conflating Go's concurrency model with its webserver implementation. Go's concurrency model (movable M:N coroutines with implicit yielding and a synchronous abstraction over async IO) is fundamentally different than the other approaches (threads and vanilla coroutines with some blend of sync and unabstracted async I/O).

Since you mentioned thread-per-connection, Go's "threads" are much lighter than even Linux threads, so you can service many more simultaneous connections (by many orders of magnitude in extreme cases). This is especially true if you're not using async I/O, and blocking I/O is the default for most of these other languages.

Re:Why Python Is Slow: Looking Under the Hood (2014) by pcwalton on Friday July 08, 2016 @01:06PM (#12057007)
In the case of an I/O bound Web server, I don't think that Go is going to appreciably result in "leaving money on the table". Python releases the GIL on I/O, which is where your time is largely spent.

> this is more efficient than spinning up an OS thread per request

Linux is very fast at spawning threads. When you're doing I/O, it doesn't matter.

Go's concurrency is not "fundamentally different" from any of the other languages. It's just an implementation of thread-per-connection in userspace. This is an implementation detail, and for a typical Web server I think it doesn't matter much.

Re:Why Python Is Slow: Looking Under the Hood (2014) by BuckRogers on Saturday July 09, 2016 @02:40AM (#12060430)
>but using Python the way you are is just leaving money on the table.

Everything leaves some performance on the table. Everything also leaves some productivity on the table too.

Python is in my estimation 20-50% more productive as a language than Go. I run my web stuff on PyPy/gunicorn/Nginx which within reason, can't be leaving much to be wanted performance-wise.

I've given Go a good-go, but I haven't found anything that strikes that balance of ~25% more productive than Go, but still grant similar performance like PyPy does for me.

Re:Why Python Is Slow: Looking Under the Hood (2014) by weberc2 on Thursday July 07, 2016 @05:57PM (#12052329)
By that logic, why optimize anything? Just use the thing that's out there that's already faster. Clearly some people think there's a benefit to dynamic languages (I'm not one of them), and they'd like to preserve that benefit while minimizing the performance impact.
Re:Why Python Is Slow: Looking Under the Hood (2014) by Animats on Thursday July 07, 2016 @06:08PM (#12052383)
Python connecting to C is used mostly to attach to large C objects that do something complicated, like OpenSSL. Math inner loop intensive things like numpy could potentially be optimized up to C speed by PyPy. (At least if you could create an array of a fixed type in Python.)
Re:Why Python Is Slow: Looking Under the Hood (2014) by cmdrfred on Thursday July 07, 2016 @05:23PM (#12052166)
Can't you? Maybe not today, but soon. https://webassembly.github.io/
Re:Why Python Is Slow: Looking Under the Hood (2014) by int_19h on Thursday July 07, 2016 @06:05PM (#12052370)