526
top 50 comments
sorted by: hot top controversial new old
[-] lime@feddit.nu 141 points 6 days ago

all programs are single threaded unless otherwise specified.

[-] firelizzard@programming.dev 48 points 6 days ago

It’s safe to assume that any non-trivial program written in Go is multithreaded

[-] kbotc@lemmy.world 16 points 6 days ago

And yet: You’ll still be limited to two simultaneous calls to your REST API because the default HTTP client was built in the dumbest way possible.

[-] firelizzard@programming.dev 1 points 4 days ago

Really? Huh, TIL. I guess I've just never run into a situation where that was the bottleneck.

[-] Scoopta@programming.dev 19 points 6 days ago

But it's still not a guarantee

[-] firelizzard@programming.dev 1 points 4 days ago

Definitely not a guarantee, bad devs will still write bad code (and junior devs might want to let their seniors handle concurrency).

[-] Opisek@lemmy.world 6 points 5 days ago

I absolutely love how easy multi threading and communication between threads is made in Go. Easily one of the biggest selling points.

[-] firelizzard@programming.dev 1 points 4 days ago

Key point: they're not threads, at least not in the traditional sense. That makes a huge difference under the hood.

[-] Opisek@lemmy.world 1 points 3 days ago* (last edited 3 days ago)

Well, they're userspace threads. That's still concurrency just like kernel threads.

Also, it still uses kernel threads, just not for every single goroutine.

[-] firelizzard@programming.dev 1 points 3 days ago

What I mean is, from the perspective of performance they are very different. In a language like C where (p)threads are kernel threads, creating a new thread is only marginally less expensive than creating a new process (in Linux, not sure about Windows). In comparison creating a new 'user thread' in Go is exceedingly cheap. Creating 10s of thousands of goroutines is feasible. Creating 10s of thousands of threads is a problem.

Also, it still uses kernel threads, just not for every single goroutine.

This touches on the other major difference. There is zero connection between the number of goroutines a program spawns and the number of kernel threads it spawns. A program using kernel threads is relying on the kernel's scheduler which adds a lot of complexity and non-determinism. But a Go program uses the same number of kernel threads (assuming the same hardware and you don't mess with GOMAXPROCS) regardless of the number of goroutines it uses, and the goroutines are cooperatively scheduled by the runtime instead of preemptively scheduled by the kernel.

[-] Opisek@lemmy.world 1 points 3 days ago* (last edited 3 days ago)

Great details! I know the difference personally, but this is a really nice explanation for other readers.

About the last point though: I'm not sure Go always uses the maximum amount of kernel threads it is allowed to use. I read it spawns one on blocking syscalls, but I can't confirm that. I could imagine it would make sense for it to spawn them lazily and then keep around to lessen the overhead of creating it in case it's needed later again, but that is speculation.

Edit: I dove a bit deeper. It seems that nowadays it spawns as many kernel threads as CPU cores available plus additional ones for blocking syscalls. https://go.dev/doc/go1.5 https://docs.google.com/document/u/0/d/1At2Ls5_fhJQ59kDK2DFVhFu3g5mATSXqqV5QrxinasI/mobilebasic

[-] Successful_Try543@feddit.org 22 points 6 days ago

Does Python have the ability to specify loops that should be executed in parallel, as e.g. Matlab uses parfor instead of for?

[-] lime@feddit.nu 54 points 6 days ago

python has way too many ways to do that. asyncio, future, thread, multiprocessing...

[-] WolfLink@sh.itjust.works 40 points 6 days ago

Of the ways you listed the only one that will actually take advantage of a multi core CPU is multiprocessing

[-] lime@feddit.nu 10 points 6 days ago

yup, that's true. most meaningful tasks are io-bound so "parallel" basically qualifies as "whatever allows multiple threads of execution to keep going". if you're doing numbercrunching in pythen without a proper library like pandas, that can parallelize your calculations, you're doing it wrong.

[-] WolfLink@sh.itjust.works 8 points 6 days ago* (last edited 6 days ago)

I’ve used multiprocessing to squeeze more performance out of numpy and scipy. But yeah, resorting to multiprocessing is a sign that you should be dropping into something like Rust or a C variant.

load more comments (1 replies)
[-] danhab99@programming.dev 10 points 6 days ago

I've always hated object oriented multi threading. Goroutines (green threads) are just the best way 90% of the time. If I need to control where threads go I'll write it in rust.

[-] lime@feddit.nu 7 points 6 days ago

nothing about any of those libraries dictates an OO approach.

load more comments (4 replies)
[-] enemenemu@lemm.ee 11 points 6 days ago

Are you still using matlab? Why? Seriously

[-] Successful_Try543@feddit.org 17 points 6 days ago

No, I'm not at university anymore.

load more comments (3 replies)
[-] Panties@lemmy.ca 7 points 6 days ago

I was telling a colleague about how my department started using Rust for some parts of our projects lately. (normally Python was good enough for almost everything but we wanted to try it out)

They asked me why we're not using MATLAB. They were not joking. So, I can at least tell you their reasoning. It was their first programming language in university, it's safer and faster than Python, and it's quite challenging to use.

load more comments (1 replies)
[-] AndrasKrigare@beehaw.org 14 points 6 days ago

I think OP is making a joke about python's GIL, which makes it so even if you are explicitly multi threading, only one thread is ever running at a time, which can defeat the point in some circumstances.

load more comments (8 replies)
[-] groknull@programming.dev 5 points 5 days ago

I initially read this as “all programmers are single-threaded” and thought to myself, “yeah, that tracks”

[-] SaharaMaleikuhm@feddit.org 23 points 5 days ago

Oh wow, a programming language that is not supposed to be used for every single software in the world. Unlike Javascript for example which should absolutely be used for making everything (horrible). Nodejs was a mistake.

[-] lena@gregtech.eu 5 points 5 days ago

Nodejs was a mistake.

More choice is always better

[-] _stranger_@lemmy.world 15 points 5 days ago* (last edited 5 days ago)

And some of those choices are mistakes.

[-] lena@gregtech.eu 6 points 5 days ago
[-] _stranger_@lemmy.world 13 points 5 days ago

I appreciate Typescript for addressing the sins of its predecessor.

[-] driving_crooner@lemmy.eco.br 4 points 5 days ago* (last edited 5 days ago)

Citations Needed: Episode 95: The Hollow Vanity of Libertarian "Choice" Rhetoric

Episode webpage: https://dts.podtrac.com/redirect.mp3/traffic.libsyn.com/secure/citationsneeded/CN95_20191205_choice_Stites_v2.mp3


Fucking Citations Needed, every time I finish an episode, someone comment something related to it.

[-] nickwitha_k@lemmy.sdf.org 25 points 6 days ago
[-] lena@gregtech.eu 5 points 5 days ago

Oooooh this is really cool, thanks for sharing. How could I install it on Linux (Ubuntu)? I assume I would have to compile CPython. Also, would the source of the programs I run need any modifications?

[-] nickwitha_k@lemmy.sdf.org 5 points 5 days ago

In this case, it's a feature of the language that enables developers to implement greater amounts of parallelism. So, the developers of the Python-based application will need to refactor to take advantage of it.

[-] computergeek125@lemmy.world 5 points 5 days ago

From memory I can only answer one of those: The way I understand it (and I could be wrong), your programs theoretically should only need modifications if they have a concurrency related bug. The global interlock is designed to take a sledgehammer at "fixing" a concurrency data race. If you have a bug that the GIL fixed, you'll need to solve that data race using a different control structure once free threading is enabled.

I know it's kind of a vague answer, but every program that supports true concurrency will do it slightly differently. Your average script with just a few libraries may not benefit, unless a library itself uses threads. Some libraries that use native compiled components may already be able to utilize the full power of you computer even on standard Python builds because threads spawned directly in the native code are less beholden to the GIL (depending on how often they'd need to communicate with native python code)

load more comments (1 replies)
[-] kSPvhmTOlwvMd7Y7E@programming.dev 17 points 5 days ago

let's be honest here, he actually means 0.01 core performance

[-] driving_crooner@lemmy.eco.br 10 points 5 days ago

I tough this was about excel and was like yeah haha!

But is about Python, so I'm officially offended.

[-] twice_hatch@midwest.social 16 points 6 days ago

don't worry it'll use all the RAM anyway

[-] SatouKazuma@programming.dev 6 points 5 days ago

I paid for all the memory. I'll use all the memory.

[-] goodbible@lemm.ee 2 points 5 days ago

JG Memoryworth

[-] lena@gregtech.eu 6 points 5 days ago

No RAM gets wasted!

[-] dan@upvote.au 11 points 6 days ago

Do you mean Synapse the Matrix server? In my experience, Conduit is much more efficient.

[-] jimmy90@lemmy.world 6 points 5 days ago

i wish they would switch the reference implementation to conduit

there is core components on the client side in rust so maybe that's the way for the future

[-] lena@gregtech.eu 4 points 5 days ago

Yep, I mean as in matrix. There is currently no was to migrate to conduit/conduwuit. Btw from what I've seen conduwuit is more full-featured.

load more comments (2 replies)
[-] h4x0r@lemmy.dbzer0.com 8 points 6 days ago
[-] tetris11@lemmy.ml 11 points 6 days ago* (last edited 6 days ago)

I prefer this default. Im sick of having to rein in Numba cores or OpenBlas threads or other out of control software that immediately tries to bottleneck my stack.

CGroups (Docker/LXC) is the obvious solution, but it shouldn't have to be

[-] alcasa@lemmy.sdf.org 5 points 5 days ago

It only took us how many years?

[-] TropicalDingdong@lemmy.world 8 points 6 days ago

Python

..so.. so you made it single threaded?

[-] Gonzako@lemmy.world 7 points 6 days ago

I'll be honest, this only matters when running single services that are very expensive. it's fine if your program can't be pararlelized if the OS does its job and spreads the love around the cpus

load more comments
view more: next ›
this post was submitted on 26 Mar 2025
526 points (100.0% liked)

Programmer Humor

22131 readers
1838 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS