News for hackers. Stuff that matters.
Re:Ask HN: Whose building on Python NoGIL? by tgma on Friday December 20, 2024 @02:36AM (#42469048)
In a strange way, Python being so bad at interpreting bytecodes and limited by GIL, plus being good at interfacing with C cheaply (unlike Go and Java,) induced a programming style that is extremely suited for data-parallel computing which is the way to efficiently scale compute in today's SIMD/GPU world. If you wanted to be efficient, you had to prepare your data ahead of time and hand it off. Any intermediate interaction with that data would ruin your performance. That's mostly how efficient Python libraries and ecosystem are built.

Weakness may have turned into a strength.

Re:Ask HN: Whose building on Python NoGIL? by grandimam on Friday December 20, 2024 @05:46AM (#42469966)
Can you elaborate more on the data-parallel computing part?
Re:Ask HN: Whose building on Python NoGIL? by francocalvo on Friday December 20, 2024 @07:16AM (#42470471)
He's probably talking about libraries like PySpark or PyFlink which are used a lot
Re:Ask HN: Whose building on Python NoGIL? by whoiscroberts on Saturday December 21, 2024 @07:18PM (#42483428)
Pyflink seems promising, I love vanilla flink but as soon as you need to debug your pyflink job pyflink becomes a hurdle. That translation layer between Python and Java can be opaque.
Re:Ask HN: Whose building on Python NoGIL? by tgma on Friday December 20, 2024 @02:08PM (#42473888)
Pretty much the entire Data Science/Machine Learning landscape from numpy, etc. to tensorflow and alike are thin wrappers over C code and if you want performance, you better batch structure your operation beforehand and minimize back and forth from Python.
Re:Ask HN: Whose building on Python NoGIL? by dec0dedab0de on Monday December 23, 2024 @09:22AM (#42494557)
The GIL is only a problem if you’re trying to access the same memory.

If you take the time to split up your data into chunks you can avoid the GIL entirely with multiprocessing. Or by handing it off to a library that does it for you. just as long as they’re not using the same python objects.

Re:Ask HN: Whose building on Python NoGIL? by ptx on Monday December 23, 2024 @10:48AM (#42495217)
Using multiprocessing adds some overhead for because of serialization, so it's slower than it would be to just hand off the Python objects directly to the workers (as you can with threads) because the process doing the parsing also has to spend time on serializing them again. So you can avoid the GIL, but it has a cost.

For example, if I parse an XML document with ElementTree, as a quick experiment, parsing the document takes ~1 second and serializing all the elements names and attributes to JSON takes an additional ~0.5 seconds. Serializing the whole ElementTree object using pickle takes ~4 seconds. Serializing it as XML takes roughly as long as parsing it.

Re:Ask HN: Whose building on Python NoGIL? by dec0dedab0de on Monday December 23, 2024 @12:47PM (#42496164)
multiprocessing has more overhead even without serialization. I just brought it up to expand on why the GIL would force someone to thinking about being data-parallel.
Re:Ask HN: Whose building on Python NoGIL? by ptx on Monday December 23, 2024 @01:11PM (#42496347)
What I was trying to say, I guess, is that the additional serialization overhead can't be parallelized, which means that parallelization with multiprocessing doesn't help much in some cases where GIL-free threading would.
Re:Ask HN: Whose building on Python NoGIL? by tgma on Wednesday December 25, 2024 @02:47AM (#42507542)
Plus, [de]serialization often needs to be done under GIL (although under non-shared GIL per process, it interferes with any other async thing that may be done in each process).

It also screws up C extensions that don't support fork and does not solve the problem of increasing TLS handshake/fanout in outbound requests by the number of cores.

The whole thing sucks in production.

Re:Ask HN: Whose building on Python NoGIL? by amelius on Saturday December 21, 2024 @04:47PM (#42482595)
Why would NoGIL change that, though? It's not like large data-parallel operations can suddenly be done efficiently in Python if you remove the GIL. The problem with GIL afaik is mostly latency problems in interactive applications.
Re:Ask HN: Whose building on Python NoGIL? by tgma on Saturday December 21, 2024 @10:27PM (#42484195)
Oh, I didn't mean to imply something will change. I am simply concurring with the parent while observing that limitation turned into a strength by established a certain ecosystem early on that fits the modern architectural developments well. I don't think that is going to change now, but had nogil been the original, it could have led to a different style of libraries being designed.
Re:Ask HN: Whose building on Python NoGIL? by crabbone on Monday December 23, 2024 @10:40AM (#42495161)
Not really... What I see in practice is that Python's shortfalls are being covered by throwing more hardware at it. (Beside of the more efficient, but also more complex: rewriting in C).

There are all kinds of micro-optimizations, as in: one has to know which Pandas operations are going to be more expensive than others, and organize the code accordingly, but these things often teach programmers the wrong ideas. It's not uncommon in Python world that a superior solution (from algorithmic perspective, i.e. the one that should use less time or space) is in practice inferior to a solution that's implemented in C. And so, writing more efficient Python code comes down to knowing which functions are faster or cheaper in some other way, but it doesn't generalize and doesn't transfer to other languages.

What usually happens in situation like this is that the developers of the language (or a product, a framework etc. that suffers a similar fate) start optimizing the bad solutions (because they are the go-to tool for their users) instead of actually improving the language (the product, the framework etc.) To give some examples of this happening in Python: there's a lot of work dedicated to the performance of lists and dicts. But, if anyone really wanted performance, they'd have to look for more specialized collections, rather than optimizing very generic ones.