Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You didn't have a hard time with the borrow checker because you used the Rust GC? Was that the argument?

Actually I left Rust and moved to Go although I love Rust much more because every struct ended up sprinkled with Arc.



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.


That would be a very interesting metric, could you grep|wc them and the locs?


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.


You're comment made my day, thanks for your work!


Hey no problem! I was glad my guess wasn’t too far off, and it was fun to go digging to check.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: