DEV Community

An example of why performance matters (with Python and Rust)

rhymes on November 05, 2018

Long intro My first real post on dev.to, in September 2017, was the following: Adventures in Tra...
Collapse
 
maxart2501 profile image
Massimo Artizzu

So he went from 1000$ a month to 0 a month, by rewriting a script with Rust.

This phrase was used when this article was tweeted. And I thought: "Wait, does it mean he was fired?!" 🤣

Collapse
 
guneyozsan profile image
Guney Ozsan

I just logged in to like this XD

Collapse
 
rhymes profile image
rhymes

hahaha like the whole concept of automating yourself out of your job :D

Collapse
 
alainvanhout profile image
Alain Van Hout

Excellent write-up :) It's nice to explorative programming leading to such cost-effective solutions.

I do have a small quibble with the title, which you already touch upon in your second paragraph: it should be 'performance can matter'. Because under the more general statement also fall things like pointlessly dense one-liners and writing scripts to save 10 seconds of typing per day.

Collapse
 
rhymes profile image
rhymes

Because under the more general statement also fall things like pointlessly dense one-liners and writing scripts to save 10 seconds of typing per day.

Ah ah true :-) Saving 10 seconds is probably a stretch too far in the performance category but I see what you mean.

I have to honest: I'm not totally against dense one liners if they actually increase performance (after careful benchmarking), provided that they are well documented and hopefully isolated from the rest of the code.

Collapse
 
alainvanhout profile image
Alain Van Hout

That's where 'fast enough' comes in: if it takes you a minute to read the documentation, another minute or two to mentally parse the code and 15 minutes of carefully checking your changes, and perhaps 2 days debugging to notice what is actually wrong, then what point is a 2 ms speedup for something that likely has no gain from that speedup? (Which is far too common an occurrence)

Or more concisely: too many people have wasted too many hours due someone who felt a need to be clever.

There are of course plenty of situations where performance is really needed. And there it's worth investing the time to do benchmarking and properly document the code. But most of the time, I'd be grateful if code were maintainable rather than clever.

Thread Thread
 
rhymes profile image
rhymes

I totally agree with you, only a comment:

That's where 'fast enough' comes in: if it takes you a minute to read the documentation, another minute or two to mentally parse the code and 15 minutes of carefully checking your changes, and perhaps 2 days debugging to notice what is actually wrong, then what point is a 2 ms speedup for something that likely has no gain from that speedup? (Which is far too common an occurrence)

Well yes, if the speed up of the oneliner is 2ms then no, it's definitely not worth it. The only upside in your case is that you might have gain a better knowledge of the system but that's due to the 2 days of debugging, not due to the oneliner :D

Thread Thread
 
alainvanhout profile image
Alain Van Hout

Indeed :-)

Collapse
 
cathodion profile image
Dustin King

This reminds me of a talk where, if I recall, a Python reporting process was sped up by first improving the algorithm, then compiling with Cython:

Collapse
 
zeerorg profile image
Rishabh Gupta

Maybe this experiment can benefit if compiled in cython 🤔

Collapse
 
rhymes profile image
rhymes

Maybe, it really depends on the code

Collapse
 
smuschel profile image
smuschel • Edited

One thing that would fit your 'stuff to think about...' list nicely is 'always choose the right tool for the job'. But then again I think everybody knows that one by now

Collapse
 
rhymes profile image
rhymes • Edited

One thing that would fit your 'stuff to think about...' list nicely is 'always choose the right tool for the job'

You're right

But then again I think everybody knows that one by now

I wouldn't bet on it, we're lazy animals of habit after all

Collapse
 
antonrich profile image
Anton

Rust's bat is sick though.

Collapse
 
rhymes profile image
rhymes

Yeah! Rust FTW I guess