Russell Cohen, a backend infrastructure engineer, writes about Rust, algorithms, data structures, and concurrency in Go and Java.
HN links his posts on linked lists in safe Rust and linear-time median finding; one commenter calls the median post a deep rabbit hole.
First off, thank you for all of the work you've put into Rust! I think the challenge that you face is that if the problem is CS101 courses, then Rust will always be unfamiliar to the majority of practicing professionals.
Cyclic/recursive datastructures are common in web services, where one needs to model bidirectional relationships ( just think of friends on a social graph ). As well as several primitive datastructures such as the O(1) LRU cache.
Checking the Rust docs out, a dev who encounters this problem for the first time will eventually need
- "Reference Cycles Can Leak Memory" https://doc.rust-lang.org/book/ch15-06-reference-cycles.html
-- caveat: what if ownership is truly bidirectional?
- "unsafe" https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html
- 5 different primitive lists which don't tell you how to make a friends graph: https://rust-unofficial.github.io/too-many-lists/infinity-double-single.html
- Someone elses attempt: https://rcoh.me/posts/rust-linked-list-basically-impossible/
- Careful reading of the LinkedList implementation to see that unsafe is probably the best approach: https://doc.rust-lang.org/beta/src/alloc/collections/linked_list.rs.html#38-43
I'm a little biased on this front, when I first picked up Rust I chose to tackle an O(1) LRU cache as a quick learning exercise. I ended up beating my head against a wall for 20 hours. However on my current project I'm analyzing the wikipedia dataset ( another bidirectional structure…
What?
I mean, there are specific sizes that will fit in the L-(N) cache.
And consequently, sizes that don't suffer from the false-sharing problem in concurrent scenarios due to this.
https://en.cppreference.com/w/cpp/thread/hardware_destructive_interference_size
There's an entire field of study devoted to cache-friendly/cache-oblivious data structures:
- https://www.microsoft.com/en-us/research/wp-content/uploads/2016/12/ccds.pdf
- https://rcoh.me/posts/cache-oblivious-datastructures/
I think the Rust people are de-emphasizing the importance of linked lists due to the glaring hole in the Rust language that makes it difficult to implement linked lists, and horribly awkward to do doubly-linked lists in safe Rust
(See https://rcoh.me/posts/rust-linked-list-basically-impossible/ )
To save face, the Rust astroturfers are now skipping around saying "Linked lists aren't important"
SEEKING WORK | Remote or Boston | https://rcoh.me | rcoh@rcoh.me
I do everything, but specialize in backend infrastructure.
- Rust, Python, Go, Scala, Java, Python, C/C++
I also do devopsy things (Ansible, Terraform, etc.)
I have a lot of experience running Kubernetes clusters and porting infrastructure to k8s.
GC is only part of the issue. Value types allow much finer control over locality, something completely lacking in Java now. And without that, you give up a lot of performance.
For example: https://rcoh.me/posts/cache-oblivious-datastructures/
The rabbit hole goes deep fast with this one!
https://rcoh.me/posts/linear-time-median-finding/
I vaguely recall learning a randomized (approximate) streaming median algorithm in grad school, but the details have left my brain…