4 ms·
Interesting how easy it is to make an operation like this run on multiple cores in Rust. Inserting a single call into a chain of functions can be enough.
by Vecr 2y ago
Interesting how easy it is to make an operation like this run on multiple cores in Rust. Inserting a single call into a chain of functions can be enough.
- MontagFTB 2y agoRust is built to be memory- and thread-safe by default. Assuming you follow the prescribed rules of the language, multithreading is “free”. Amdahl’s Law still gets a vote, but at least your app won’t blow up in your face.
- jjtheblunt 2y ago> Assuming you follow the prescribed rules of the language, multithreading is “free”. I'm wondering if you're referring to the async await addition from a few years back, to use of Tokio's crate(s), or something else.
- kevincox 2y agoI think they are referring to this section: https://chevyray.dev/blog/creating-175-fonts/#automatic-kerning https://chevyray.dev/blog/creating-175-fonts/#automatic-kern... In this case they are not using async but Rayon which provides some easy primitives for splitting tasks into smaller parts that can run in parallel. In this case the par_iter and par_extend calls.
- hypeatei 2y agoIIRC, async/await in most languages doesn't imply multi threading, it just allows other work to be done on the same thread simultaneously.
- vips7L 2y agoIt's not really unique to Rust. Scala and Java both support this out of the box.
- Filligree 2y agoYeah, but in Rust it’s far less likely to explode in your face.
- johnisgood 2y agoOr in Ada. Ada 202x[1] brings enhancements like the parallel block, making parallelism easier to express, somewhat similar to Rust's approach but still with Ada's emphasis on clarity and safety. [1] https://blog.adacore.com/ada-202x-support-in-gnat https://blog.adacore.com/ada-202x-support-in-gnat (2020) There may be more enhancements that I may not know about or remember, although I did mention Ada's constructs for safe concurrent code before.
- dwattttt 2y agoThe stronger guarantees/performance fall out of the stronger lifetime/ownership model, combined with errors around ambiguous/invalid lifetimes being a compiler error. In other languages those violations are things you have to run a race detector and actually evoke the condition to find, or you abandon fine grained/tracked ownership and use garbage collection.
- vips7L 2y agoNone of that matters with this code. There are no lifetimes here and in fact there is no ownership either. Everything is a primitive char. They’re always copied and no mutation occurs. It’s pure computation. You could write this code exactly the same way in those languages.
- dwattttt 2y agoTrue. You could write it in C or asm too, and it would be about as simple. But there's still a difference that if they weren't all primitive (and you can't always rely that they will be), you'll know it won't work straight away in Rust, whereas in the others you need to walk every data type involved to make sure ownership is clear (or rely on a garbage collector to save you).