Follow

- Have a deeply recursive function in
- Rewrite it naively in
- Compile with `cargo build --release`
- Notice it is now 10× *slower*

…hmm, that wasn't what I expected!

@codesections
I think #Rust has no tail call optimization. Can you share the code?

In case anyone has any thoughts about why the rust version could be so much slower than the javascript version, I decided to ask about it on r/rust here: reddit.com/r/rust/comments/ady

cc: @zalandocalrissian that has links to the code

Wow, the community really is amazing! I posted a fairly beginner question on r/rust just now, and within 10 minutes I got 8 comments—7 of them were attempted solutions, 6 of them were *correct* solutions, and 2 of them had full, running code samples/diffs.

And *none* of them called me dumb or implied I don't know how to program—even though I made a classic beginner mistake (solving ownership issues with excessive use of `clone()` instead of by understating my code better)

@codesections genuinely considering going rust just to be treated be like human when programming :blobshh: I'm happy for you!

@codesections It's a good thing that some programming communities are treating beginners with respect.

@codesections again, some improvements to your (new version of) code: play.rust-lang.org/?version=st (notes inline)

On my machine it is about 10% faster than your version, must be because it doesn't do the conversions between usize/i32/Option<i32> everywhere.

And again the Rust and JS versions are doing a similar number of allocations, that is why the performance is similar.

@bugaevc

Thanks! I took your changes and ran with them—new code here: gist.github.com/codesections/9.

The execution time is now ~20% of the JavaScript time (about 3% of my original version with all the `clone()`s)

@codesections I love the community but can leave the language. Great role model for any other language or community.

@DistroJunkie just curious: what don't you like about the language?

@codesections I just don't. Don't like many of the new languages and have grown tired of them. Seems like we're constantly making new languages that supposedly do new and wonderful things but they really don't. Then my coworkers make the argument that if we used this new language, we'll be able to do wonderful things. We do, and then don't and then must fix new and horrible things. I contend that any one of many of our old languages will fit the bill. I vote for C. Old Graybeard.😃

@codesections Also, I hate garbage collection. It's garbage. It's a crutch. I can use a language that has or had a garbage collector but I find the fact that it has one repulsive.

@codesections Just look at all of the trendy languages that have come and gone over the years. Seems like they come and go faster and faster as the years go by. I wish we'd pick one mature universal language and run with it. And stop it with the new versions of languages. If we have to update it (read fix it), it probably wasn't all that good to begin with. Sorry, I've turned this into a rant. I'll stop now.😃

@DistroJunkie @codesections The world will not end in fire and brimstone, nore nuclear fallout, nor global warming and floods, but rather in DSLs

@DistroJunkie
Those are all opinions I can respect, even if I don't entirely agree.

And if your objection is based on change, I can certainly understand not liking a language that's committed to a new release every six weeks!

Of course, I'm coming from the web dev world, and from that perspective, rust seems positively traditional—at least the ecosystem doesn't turn over every ~18 months!

@codesections I'm not opposed to change with a definite purpose and reason. Change for change's sake, not so much a fan.

To me, the real power of Rust is crates. Fortunately, they have many converts to give them staying power.

Much like buying new trendy golf clubs is not going to improve a bad golfer's game, using the newest trendy programming language is not going to improve a bad programmer's code. Unless they are reusing good code from other programmers.😃

Sign in to participate in the conversation
Fosstodon

Fosstodon is a Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.