News for hackers. Stuff that matters.
Re:How Rust optimizes async/await by rapsey on Monday August 19, 2019 @01:19PM (#20739651)
Honestly I don’t get it why simply using mio (epoll, kqueue, iocp wrapper) is so unpopular.
Re:How Rust optimizes async/await by oconnor663 on Monday August 19, 2019 @01:33PM (#20739785)
See these examples of how async/await simplifies looping and error handling: https://docs.rs/dtolnay/0.0.3/dtolnay/macro._01__await_a_min.... Await syntax makes it much easier to compose asynchronous code from different libraries, in the same way that ordinary function calls compose synchronous code. Talking to epoll/mio directly is certainly possible, but it's hard to make two different libraries work well together if they both need to talk to a single epoll handle.
Re:How Rust optimizes async/await by rapsey on Monday August 19, 2019 @01:37PM (#20739832)
Yeah but you’re talking about things not even stable. Old tokio with closures is terrible imo.
Re:How Rust optimizes async/await by steveklabnik on Monday August 19, 2019 @06:35PM (#20742422)
It’s extremely close to being stable; it just missed a release train, because there’s some last minute polish that needs to be done. It will be on its way soon!
Re:How Rust optimizes async/await by jnordwick on Monday August 19, 2019 @02:07PM (#20740145)
everybody always points to the 5 line basics, never to how complex async/await gets in a real system with timers, tuneouts, multiple errors types that need to be handled in different ways, heartbeats, side channel info, etc... It isn't better at that point.

Cool, you can write a 5 line echo server easier, but good luck with a high performance server handling important transactions.

(If there is documentation on how to do some of these or good example code, please point me to it, because my last attempt at getting send/rcv heartbeats efficiently didn't work.)

Re:How Rust optimizes async/await by jcranmer on Monday August 19, 2019 @02:42PM (#20740499)
The networking implementations I've had to do were all made a lot easier moving to async/await from hand-written state machines. It's a reduction in LOC terms of 6x or so, and the logic is much, much easier to follow.

State machines are viable if your transition function is such that effectively every combination of (state, input) leads to a different state. If the transition function is mostly describing "go to the (single) next state or error," then you're essentially asking the user to do a lot of bookkeeping that compilers are good at and users are bad at.

Re:How Rust optimizes async/await by littlestymaar on Monday August 19, 2019 @02:52PM (#20740599)
Having ported a full peer-to-peer engine in JavaScript from old-school callbacks to async/await, I strongly disagree with your comment.

Async/await really shines when the complexity arises.

Re:How Rust optimizes async/await by pcwalton on Monday August 19, 2019 @02:33PM (#20740408)
People are doing a lot more with async/await than five-line echo servers. They're converting entire codebases and seeing dramatic reductions in noise.
Re:How Rust optimizes async/await by leshow on Monday August 19, 2019 @04:02PM (#20741277)
Probably because you're just looking at examples; that's selection bias. The combinators/manual implementing Future approach to async IO gets even worse at scale, async/await is infinitely easier. If you don't like it, nobody is forcing you to use it.
Re:How Rust optimizes async/await by pcwalton on Monday August 19, 2019 @01:24PM (#20739705)
Because most people don't like writing state machines by hand.
Re:How Rust optimizes async/await by rapsey on Monday August 19, 2019 @01:35PM (#20739810)
Pre-await Tokio code looks way worse to me.
Re:How Rust optimizes async/await by jcranmer on Monday August 19, 2019 @03:08PM (#20740770)
A lot of that, I suspect, is that Rust's borrow checker makes specifying ownership correctly for callback chains extremely painful and unergonomic.

In my experience, closure-based async programming is only sufficiently painless in managed languages to be worth using. When you're dealing with manual memory management (or, rather, smart pointer memory management), you spend a lot more time trying to make the captures hold onto stuff.

Re:How Rust optimizes async/await by tmandry on Monday August 19, 2019 @03:50PM (#20741165)
I'd agree with this, and emphasize the point that this stuff is really tricky to get right without GC. Fighting the borrow checker is somewhat expected when you're dealing with this level of inherent complexity in your memory management.

One of the key reasons for shipping async/await is that it erases almost all of this difficulty and lets you write straight-line code again.