News for hackers. Stuff that matters.
Re:Rusty Ownership and the Lifecycle’s Stone by mplanchard on Sunday November 27, 2022 @07:50PM (#33768609)
No, there’s no argument. The statement was that lifetimes aren’t that hard, and that when you do get stuck there are escape hatches. The escape hatches are especially useful when you’re still learning.

FWIW I write Rust professionally now, and in our entire codebase we have maybe four or five data structures containing Arcs, specifically where objects are spawned as Futures on other threads.

Re:Rusty Ownership and the Lifecycle’s Stone by KingOfCoders on Monday November 28, 2022 @01:58AM (#33770527)
That would be a very interesting metric, could you grep|wc them and the locs?
Re:Rusty Ownership and the Lifecycle’s Stone by mplanchard on Monday November 28, 2022 @11:16AM (#33775447)
Sure!

Tokei says that we've got ~76k lines of Rust.

I used ripgrep to find occurrences of `Arc::` (to exclude type signatures and only find constructors) and then just gave it a quick manual look to exclude tests and benchmarks.

This leaves me with:

- one data structure that contains general application state and contextual information, which is created at application startup and shared across all tasks/threads

- one data structure for accumulating results that is shared across threads. This is an Arc<Mutex<u64, SomeEnum>>. The less common of the two enum variants is an Arc<BTreeMap>.

- one data structure used to pass a database connection in to a context where it'll be used to spawn async tasks

All told, we've only got four places in production paths where we construct a new Arc. One of those four is only called once in the life cycle of the application, while the others are called for any given invocation.

Re:Rusty Ownership and the Lifecycle’s Stone by KingOfCoders on Tuesday November 29, 2022 @01:19AM (#33784260)
You're comment made my day, thanks for your work!
Re:Rusty Ownership and the Lifecycle’s Stone by mplanchard on Wednesday November 30, 2022 @10:33AM (#33802096)
Hey no problem! I was glad my guess wasn’t too far off, and it was fun to go digging to check.