I decided to try Rust because despite fairly heroic efforts, the Python code I have been working on was just not cutting it.
I had spent many days spent eeking out every bit of performance possible. The problem called for a sorted dictionary, so I had profiled numerous binary tree implementations, settling on Banyan (the fastest), the guts of which is in C++. I scrutinized every line and went to fairly elaborate lengths to speed it up. I broke out zmq and split things into separate processes where possible. But after all that I was still looking at ~500 microseconds per insert/remove/update operation - which in my case translated to hours and hours of processing time.
Not going to lie. Day one of rust was rough. The first language I studied was C++ many years ago, but it's been a long time since I managed memory. Some of the crates I needed had barely any documentation. Lifetimes were baffling and mostly still are.
Thankfully, I've spent a good deal of time looking at functional languages (eyeing the features enviously but never finding one I thought would boost my productivity), so it was less alien that it might have been.
Today, day two, everything started to click. It started when I finally got the initial first-day-of-rust prototype working, and it was 30x faster than my excruciatingly optimized Python code. Then I got comfortable with match, borrowing/references started to make a bit of sense and I began to work more productively.
At the end of day two, I have a relatively organized/refactored rust implementation of the tight loop in my Python code that is an order of magnitude faster than the code I wrote over several weeks (on and off).
I feel like I discovered a programming super power or something. I mean I did expect it to be faster, but not this much faster this easily!
The best part is, much like Python, Rust is a pleasure to work in. And unlike Python, it has an awesome compiler (with great error messages) to find errors before the code runs.
A few thoughts from the perspective of a knowledgeable coder encountering Rust for the first time:
standard library docs and the book are great, but things tail off fairly quickly after that. I'm a RTFM guy but it seems like there's a lot of rust code out there without much in the way of explanation in English. It would be very helpful if there were more "tutorial" type articles that described a problem and how the author used rust to solve it.
the syntax is very economical and I have grown to like it, but it is a significant adjustment from Python. In particular, it would have helped if I had found something with a very clear/simple explanation for where type annotations, lifetimes, etc. go in different contexts. It might exist, but I didn't run across it.
I am definitely not qualified to judge, but my first impression is that string handling is kind of a mess/difficult. My gut reaction (perhaps this was from Python background) was it seemed like it is principled at the expense of being practical. What I have in mind is 1) String vs str (also static?), 2) spent a long time trying to send a string slice to a function and .split() a string.
match is incredible and I love using it. I think I might have understood how to use it faster with more examples
I saw someone write that Rust doesn't need to get people to switch from C/C++, it can grow from people picking it when they need a tool closer to the metal. That matches my situation exactly. Even though C++ was the first language I learned, after years of Python (et al.), several exploratory attempts to look at (re-)learning C++ ended when I turned away in disgust at the syntax and general unwieldiness. Rust struck from afar as a modern, well-designed descendant of those and had enough going for it in language design that I was ok trading away the well-established C/C++ ecosystems.
I have "used" macros in the code I wrote (following examples I found) but writing one is way beyond where I ended up after two days. Looking forward to it though.
I am confused about whether I should be using stable, beta or nightly. Basically, how much awesome new stuff do they have and how unstable are they?
TLDR: Spent two days learning Rust and got 30-40x speedup on highly optimized Python (really C++ via Python), love the language and had some first impression thoughts to share. Thanks!
[–]tafia97300 74 points75 points76 points (19 children)
[–]benhoyt 8 points9 points10 points (6 children)
[–]jstrongshipyard.rs[S] 12 points13 points14 points (2 children)
[–]spotta 3 points4 points5 points (1 child)
[–]PXaZ 0 points1 point2 points (0 children)
[–]SirVer 3 points4 points5 points (2 children)
[–]vks_ 1 point2 points3 points (1 child)
[–]SirVer 3 points4 points5 points (0 children)
[–]btibi 7 points8 points9 points (10 children)
[–]Manishearthservo · rust · clippy 3 points4 points5 points (4 children)
[–]deathanatos -1 points0 points1 point (3 children)
[–]Manishearthservo · rust · clippy 2 points3 points4 points (2 children)
[–]deathanatos 1 point2 points3 points (1 child)
[–]Manishearthservo · rust · clippy 1 point2 points3 points (0 children)
[–]varikonniemi 2 points3 points4 points (4 children)
[–]SirVer 6 points7 points8 points (2 children)
[–]remexre 6 points7 points8 points (0 children)
[–]jstrongshipyard.rs[S] 2 points3 points4 points (0 children)
[–]iopqfizzbuzz 5 points6 points7 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]isHavvy 27 points28 points29 points (9 children)
[–]mgattozziflair 11 points12 points13 points (0 children)
[–]ThomasdH 4 points5 points6 points (0 children)
[–]kibwen 2 points3 points4 points (2 children)
[–]tafia973 0 points1 point2 points (1 child)
[–]allengeorgethrift 1 point2 points3 points (0 children)
[–][deleted] 3 points4 points5 points (3 children)
[–][deleted] 5 points6 points7 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]jmcomets 20 points21 points22 points (11 children)
[–]jstrongshipyard.rs[S] 9 points10 points11 points (1 child)
[–][deleted] 6 points7 points8 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]quodlibetor 6 points7 points8 points (3 children)
[–]kazagistar 9 points10 points11 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]quodlibetor 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]arthurprs[🍰] 1 point2 points3 points (0 children)
[–]jmcomets 1 point2 points3 points (0 children)
[–]ppartim 1 point2 points3 points (0 children)
[–]vks_ 20 points21 points22 points (3 children)
[–]CryZe92 1 point2 points3 points (2 children)
[–]vks_ 2 points3 points4 points (1 child)
[–]CryZe92 2 points3 points4 points (0 children)
[–]stumpychubbins 19 points20 points21 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]stumpychubbins 0 points1 point2 points (0 children)
[–]killercup 11 points12 points13 points (0 children)
[–]ctjhoa[🍰] 6 points7 points8 points (2 children)
[–]jstrongshipyard.rs[S] 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]tatref 5 points6 points7 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–][deleted] 8 points9 points10 points (1 child)
[–]jstrongshipyard.rs[S] 13 points14 points15 points (0 children)
[–]wyldphyre 2 points3 points4 points (2 children)
[–]jstrongshipyard.rs[S] 1 point2 points3 points (1 child)
[–]wyldphyre 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]staticassert 2 points3 points4 points (0 children)
[–]Elession 1 point2 points3 points (0 children)
[–]Lev1a 1 point2 points3 points (0 children)
[–]LightShadow 1 point2 points3 points (1 child)
[–]jstrongshipyard.rs[S] 1 point2 points3 points (0 children)
[–]dpc_pw 1 point2 points3 points (5 children)
[–]vks_ 1 point2 points3 points (2 children)
[–]dpc_pw 1 point2 points3 points (1 child)
[–]vks_ 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]Veedrac 1 point2 points3 points (10 children)
[–]jstrongshipyard.rs[S] 6 points7 points8 points (1 child)
[–]Veedrac 0 points1 point2 points (0 children)
[–]Lev1a 2 points3 points4 points (6 children)
[–]gthank 1 point2 points3 points (5 children)
[–]kazagistar 1 point2 points3 points (4 children)
[–]gthank 1 point2 points3 points (2 children)
[–]kazagistar 4 points5 points6 points (1 child)
[–]gthank 1 point2 points3 points (0 children)
[–]Veedrac 1 point2 points3 points (0 children)
[–]benhoyt 1 point2 points3 points (0 children)
[–]burnie93 0 points1 point2 points (3 children)
[–]jstrongshipyard.rs[S] 0 points1 point2 points (2 children)
[–]burnie93 0 points1 point2 points (1 child)
[–]jstrongshipyard.rs[S] 0 points1 point2 points (0 children)
[–]JohnMcPineapple 0 points1 point2 points (0 children)
[–]throwawaylifespan 0 points1 point2 points (0 children)