frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

A Few Words About Async

https://yoric.github.io/post/quite-a-few-words-about-async/
37•vinhnx•6h ago

Comments

neonsunset•4h ago
Thank you for the article. I noticed the statement

> A second drawback is that async/await has a performance cost. CPU-bound code written with async/await will simply never be as fast or as memory-efficient as the equivalent synchronous code.

If you are interested, .NET is actively improving at this and .NET 11 will ship with "Runtime Async" which replaces explicitly generated state machines with runtime suspension mechanism. It's not """zero-cost""" for now (for example it can block object escape analysis), and the async calling convention is different to sync, but the cost is massively reduced, the calls can be inlined, optimized away, devirtualized and more in the same way standard sync calls can. There will be few drawbacks to using async at that point, save for the syntax noise and poor default habit in .NET to append Async suffix to such methods. In your own code you can write it tersely however.

As for Rust, it also can optimize it quite well, the "call-level overhead" is much less of a problem there, although I have not studied compiler output for async Rust in detail so hopefully someone with more familiarity can weight in.

sema4hacker•2h ago
> I’ll try and write a followup with benchmarks.

That would definitely keep the story from being all-hat-and-no-cattle. I can't recall reading something with so many alternate versions of how to implement something but with zero benchmarks.

jiggunjer•2h ago
Recently had to familiarize myself with python async because a third party SDK relies on it.

In many cases the lib will rely on threads to handle calls to synchronous functions, got me wondering if there's a valid use case for running multiple async threads on a single core.

travisgriggs•2h ago
That was “quite a few” words. I wish the author had taken more time with Elixir/Erlang.

Languages like rust/python that use lots of reserved keywords, especially for control flow seem to have reached for that arrow to solve the “event loop” problem as described.

In BEAM languages, that very event loop stays front and center, you don’t have this awkward entanglement between reserved keywords and event loop. If you want another chunk of thing to happen later because of an event, you just arrange for an event of that nature to be delivered. No callbacks. No async coloring. Just events. The solution to the event problem is to double down and make your event loop more generally usable.

vlovich123•2h ago
> In practice, things are a bit more complicated. In fact, I don’t know of any async/await embedding on top of io_uring in any language yet, because it doesn’t quite match this model. But generally, that’s the idea.

Glommio and monoio are async runtimes in rust on top of io_uring and Tokio has an optional io_uring backend. Does that not count? This is such a well researched article that this kind of statement makes me think I’m missing something - surprising the author would get this wrong.

koakuma-chan•10m ago
As far as I know those libraries only implement basic things. They don't use registered buffers, registered file descriptors, etc, and don't implement advanced features like chained operations.
unscaled•58m ago
This is a pretty in depth overview of a complex topic, which unfortunately most people tends to dumb down considerably. Commonly cited articles such as "What Color is Your Function?" or Revisiting Coroutines by the de Moura and Ierusalimschy are insightful, but they tend to pick on a a subset of the properties that make up this complex topic of concurrency. Misguided commentators on HN often recommends these articles as reviews, but they are not reviews and you are guaranteed to learn all the wrong lessons if you approach them this way.

This article looks like a real review. I only have one concern with it: It oversells M:N concurrency with green threads over async/await. If I understand correctly, it claims that async/await (as implemented by Rust, Python C# and Kotlin - not JavaScript) is less efficient (both in terms of RAM and CPU) than M:N concurrency using green threads. The main advantages it has is that No GC is required, C library calls carry no extra cost and the cost of using async functions is always explicit. This makes async/await great for a systems language like Rust, but it also pushes a hidden claim that Python, C# and Kotlin all made a mistake by choosing async/await. It's a more nuanced approach than what people take by incorrectly reading the articles I mentioned above, but I think it's still misguided. I might also be reading this incorrectly, but then I think the article is just not being clear enough about the issues of cost.

To put it shortly: Both green threads and async/await are significantly costlier than single-threaded code, but their cost manifests in different ways. With async/await the cost mostly manifests at "suspension points" (whenever you're writing "await"), which are very explicit. With green threads, the cost is spread everywhere. The CPU cost of green threads includes not only the wrapping C library calls (which is mentioned), but also the cost of resizing or segmenting the stack (since we cannot juts preallocate a 1MiB stack for each coroutine). Go started out with segmented stacks and moved on to allocating a new small stack (2KiB IIRC) for each new goroutine and copying it to a new stack every time it needs to grow[1]. That mechanism alone carries its own overhead.

The other issue that is mentioned with regards to async/await but is portrayed as "resolved" for green threads is memory efficiency, but this couldn't be farther from the truth: when it's implemented as a state machine, async/await is always more efficient than green threads. Async/await allocates memory on every suspension, but it only saves the state that needs to be saved for this suspension (as an oversimplification we can say it only saves the variables already allocated on the stack). Green threads, on the other hand, always allocate extra space on the stack, so there would always be some overhead. Don't get me wrong here: green threads with dynamic stacks are considerably cheaper than real threads and you can comfortably run hundreds of thousands of them on a single machine. But async/await state machines are even cheaper.

I also have a few other nitpicks (maybe these issues come from the languages this article focuses on, mainly Go, Python, Rust and JavaScript)

- If I understand correctly, the article claims async/await doesn't suffer from "multi-threading risks". This is mostly true in Rust, Python with GIL and JavaScript, for different reasons that have more to do with each language than async/await: JavaScript is single-threaded, Python (by default) has a GIL, and Rust doesn't let you have write non-thread-safe code even if you're using plain old threads. But that's not the case with C# or Kotlin: you still need to be careful with async/await in these languages just as you would be when writing goroutines in Go. On the other hand, if you write Lua coroutines (which are equivalent to Goroutines in Go), you can safely ignore synchronization unless you have a shared memory value that needs to be updated across suspension points.

- Most green thread implementations would block the host thread completely if you call a blocking function from a non-blocking coroutine. Go is an outlier even among the languages that employ green threads, since it supports full preemption of long-running goroutines (even if no C library code is called). But even Go only added full support for preemption with Go 1.14. I'm not quite since when long-running Cgo function calls have been preemptible, but this still shows that Go is doing its own thing here. If you have to use green threads on another language like Lua or Erlang, you shouldn't expect this behavior.

[1] https://blog.cloudflare.com/how-stacks-are-handled-in-go/

valcron1000•21m ago
> async/await is also available in a bunch of other languages, including F#, C#8, Haskell[...]

Haskell (GHC) does not provide async/await but uses a green thread model.

The new hot job in AI: forward-deployed engineers

https://www.ft.com/content/91002071-7874-4cb7-9245-08ca0571c408
1•jamesblonde•4m ago•0 comments

VisualDiffer Released Open Source

https://github.com/visualdiffer/visualdiffer
1•dafi70•8m ago•1 comments

It's Either Medium or Me That Doesn't Know What Trending Means

https://medium.com/luminasticity/its-either-medium-or-me-that-doesn-t-know-what-trending-means-c2...
1•bryanrasmussen•14m ago•0 comments

Cloudflare just got faster and more secure, powered by Rust

https://blog.cloudflare.com/20-percent-internet-upgrade/
2•signa11•15m ago•0 comments

Universal Code Translator: Translate Between Any Paradigm

https://github.com/jaibabaneemkaroli-1/universal-code-translator
1•babaneemkaroli•20m ago•1 comments

Gt: [experimental] multiplexing tensor framework

https://github.com/bwasti/gt
1•brrrrrm•21m ago•0 comments

Introducing use-less-react (ReactJS and OOP)

https://www.npmjs.com/package/@dxbox/use-less-react
1•fab_fog•25m ago•0 comments

VORAvideo – All-in-One AI Video Generator (50% Launch Off)

https://voravideo.com/
1•nicohayes•27m ago•1 comments

Global Crossing Is Reborn

https://pracap.com/global-crossing-reborn/
1•baxtr•27m ago•0 comments

Intervaltree with Rust Back End

https://github.com/Athe-kunal/intervaltree_rs
1•athekunal•33m ago•1 comments

The Data Centers That Train A.I. and Drain the Electrical Grid

https://www.newyorker.com/magazine/2025/11/03/inside-the-data-centers-that-train-ai-and-drain-the...
2•jdkee•36m ago•1 comments

Nginx Unit Development Ended

https://github.com/nginx/unit
2•srigi•36m ago•0 comments

Las Vegas Police Debut Cybertruck Patrol Fleet

https://www.autoblog.com/news/las-vegas-police-debut-the-worlds-first-tesla-cybertruck-patrol-fleet
2•geox•45m ago•0 comments

Why do AI models use so many em-dashes?

https://www.seangoedecke.com/em-dashes/
4•ahamez•46m ago•1 comments

Dodgers Beat the Blue Jays

https://www.latimes.com/sports/dodgers/story/2025-11-01/dodgers-defeat-toronto-blue-jays-game-7-c...
1•milleramp•50m ago•0 comments

I'm looking for a guest blog author about EIN letters

https://fromzerotollc.com/step/after-receiving-your-ein-letter
1•erayalakese•52m ago•1 comments

Bostwick Consistometer

https://en.wikipedia.org/wiki/Consistometer
1•ggm-at-algebras•53m ago•0 comments

FBI Ousts Leader as Patel Fumes over Attention to Agency Jet Use

https://news.bloomberglaw.com/us-law-week/fbi-ousts-leader-as-patel-fumes-over-attention-to-agenc...
3•salkahfi•57m ago•1 comments

LTX2 Video – Open-Access AI Video Generator with Synchronized Audio

https://ltx2.video
1•xbaicai•57m ago•1 comments

From hours to seconds: AI tools to detect animal calls

https://www.seangoedecke.com/animal-call-audio-recognition/
1•vismit2000•57m ago•0 comments

Show HN: Picuki – Your Instagram Editor and Viewer

https://instapicuki.com
1•linovaSector•1h ago•0 comments

80% of NYC-area air traffic controllers absent amid 'surge' in callouts: FAA

https://abcnews.go.com/US/delays-safety-concerns-shortages-air-traffic-controllers/story?id=12705...
2•dataflow•1h ago•0 comments

How Silicon Valley enshittified the internet

https://www.theverge.com/podcast/809081/enshittification-cory-doctorow-platforms-ai-monopoly-big-...
4•thefilmore•1h ago•1 comments

Are Unikernels the Answer for Next-Gen AI Cloud Workloads?

https://thenewstack.io/are-unikernels-the-answer-for-next-gen-ai-cloud-workloads/
2•transpute•1h ago•0 comments

Show HN: AI ASMR – Template‑based ASMR video generator

https://www.ai-asmr.co
1•Lucas1991•1h ago•0 comments

Distilled Prompt Engineering Optimization

https://dimaggi.com
1•tenywan•1h ago•0 comments

Open Catalyst Project

https://opencatalystproject.org/
1•mfiguiere•1h ago•0 comments

Best Digital Marketing Institute in Allahabad – Ndmit Prayagraj

https://ndmit.com/ai-driven-data-science/
1•karan868•1h ago•0 comments

CLI to manage your SQL database schemas and migrations

https://github.com/gh-PonyM/shed
8•PonyM•1h ago•3 comments

PyTorch Helion

https://pytorch.org/blog/helion/
1•jarbus•1h ago•0 comments