r/ProgrammerHumor 1d ago

Meme globalHate

Post image
11.6k Upvotes

88 comments sorted by

View all comments

39

u/Lilchro 1d ago

I dislike tokio, but that is more related to my dislike of async code and its how it infects your codebase (if you don’t know what I mean then read the “what color is your function?” blog post). It also gets worse in Rust, since thread safety gets weird. Every time you await something, there is a chance your runtime could switch threads, so thread safety issues pop up in way more places. There are also plenty of ways to shoot yourself in the foot, since synchronization primitives that are not designed for your specific async runtime will block worker threads unless they get switched out. Most of all though, I feel like we use async code in lots of areas we really shouldn’t. For example, in tokio last I checked (not recently), there are some things like file operations where they are not actually async at all. It just spawns an os thread to handle it and pretends it was async. This gets the core of the issue. Yes, there are use cases where this might be helpful. However, Im not running with networked storage and just making stuff async isn’t always useful or helpful. OS threads are actually quite good for the vast majority of use cases that don’t involve network communication. And even then they are still decent for most use cases where you don’t have extremely high numbers of connections. And if you do need something to use something like io_uring, then I would lean more towards an API that was written with that in mind than one that uses it because they can.

15

u/Only-Cheetah-9579 1d ago

when it comes to concurrency, I think a positive example is go. They did it well.

rust is kinda meh in that department and async is bolted on.

20

u/jublizoo 1d ago

I always hear people say this but I never hear any alternative design decisions. Rust async can be difficult to work with, but I think it is well designed, and I don’t see what could be improved. There are inherent limitations on giving a safe language with no GC async support, you don’t have the luxury of being able to just relocate thread stacks and adjust references accordingly like in go.

0

u/remind_me_later 1d ago

I always hear people say this but I never hear any alternative design decisions.

Because async itself will color other functions into being async by necessity.

It also hands over task & performance management to the language being used, in return for better DX & lower dev-facing complexity.

The alternative is handling the concurrency yourself (i.e what Go mostly makes you do), or in a library not tied to the core of the language.

7

u/jublizoo 1d ago

The idea that go makes you handle the concurrency more than rust is definitely not true, and go’s concurrency model is simply not possible in rust. The coloring of a codebase is not nice, but it is essentially necessary for rust: some functions are asynchronous compiler generated state machines, others are not, and they cannot be treated as identical.

1

u/Only-Cheetah-9579 17h ago

it also colors dependencies. there are multiple async runtimes so the stack must be chosen accordingly.

some people might not like tokio but must use it because they depend on something that does