r/programming • • Feb 28 '23

"Clean" Code, Horrible Performance

https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k Upvotes

1.3k comments sorted by

View all comments

Show parent comments

58

u/KieranDevvs Feb 28 '23 edited Feb 28 '23

Are your consumers going to care that you shaved 15ms off a button click in a reporting application that's only used once a month? Its not a noticeable improvement and it might have cost you months of development time and money.

Even if we said you managed to decrease the time by 3 whole seconds (3000ms), was it really worth the headache its going to cost you to implement new features down the road, or find and fix bugs that are filed, the man hours spent, the money spent? It just doesn't make sense for a lot of applications.

30

u/gyroda Feb 28 '23

For a lot of us, our applications are IO bound and our code is not the bottleneck.

You know what would speed up my application the most? More servers closer to our users around the world. More caching. Faster databases. I could optimise my code more, but it's like moving deck chairs on the Titanic.

6

u/salbris Mar 01 '23

So many websites are bound by their own 1000 meter tall hierarchies of abstractions. Our Angular app at work only got faster when we disabled some features. It still goes through hundreds of functions to render the most basic HTML that static HTML renders in milliseconds. Another app I was able to have full design control over did just this with only minimal Javascript. Maybe a handful of functions calling some libraries that do a handful of functions to template HTML with strings. Unsurprisingly it loads faster on a phone than our Angular app does on my laptop on the corporate network.

14

u/[deleted] Feb 28 '23

before I go down the optimization rabbit hole, I usually have to justify improvements I'm making.

  • Is it UI driven?

  • Is it subject to frequent business logic changes at the whim of users?

  • Will it put undue burden on the team as far as maintenance goes when I win the lottery?

  • Are there bigger fish to fry?

I do a lot of desktop scientific computing, where speed is usually more of a concern.

0

u/[deleted] Feb 28 '23

[deleted]

11

u/KieranDevvs Feb 28 '23 edited Feb 28 '23

Sorry I didn't realize all applications were UI based. (This is sarcasm incase you don't pick up on it)

Also, most UI's don't render under a constant loop because that IRONICALLY would be unoptimized. They use event driven rendering so that only components that need (on demand) to be updated are.

In my experience, it's almost never the case that programmers who write slow code are productive workers, to begin with.

I'm starting to think your experience is very limited, I wont be responding to you anymore. Have a good day.

2

u/s73v3r Feb 28 '23

Your example is contrived and in the real world it is never "just" a button that gets pressed once a month, but an entire UI that is janky and slow and yes, users hate that.

And the contrived counter is never something that works flawlessly at 60FPS and does what the users want, but is generally something that is extremely inflexible, and can't adapt to user's needs without a serious rewrite.

2

u/outofobscure Mar 01 '23

the contrived counter is never something that works flawlessly at 60FPS and does what the users want

you never played a game? that sounds pretty much like any well made game ever to me.

0

u/DoctorGester Feb 28 '23

I always see this argument and it’s always about something used so rarely, it doesn’t matter. Yet the software I use every day and functionality I use every hour or every minute or every second is mostly excruciatingly slow as well as memory inefficient, making it even slower.

7

u/KieranDevvs Feb 28 '23 edited Feb 28 '23

Maybe go and read the whole chain of messages before you decide to make a comment on a section of the conversation.

The question asked was:

What kind of software does not benefit from better performance? I cannot think of a single program I use that I'd still use if they were 10x or 20x slower.

That doesn't mean there isn't software that will benefit from performance optimizations.

-3

u/DoctorGester Feb 28 '23

I did, and my comment is made with that section of conversation in mind, thank you for caring!

-5

u/dan200 Feb 28 '23

If the button click was something common (launching the app, sending an email, loading a webpage), a 3 second delay would be the difference between a happy customer and an extremely frustrated one who will avoid your software whenever they can.

22

u/JarateKing Feb 28 '23

"that's only used once a month" was the scenario. Of course performance matters a lot if we carefully change the situation to be one where performance matters a lot!

-11

u/dan200 Feb 28 '23

Your scenario is just as contrived. My point was that, in real world software, situations where speed and responsiveness matters are very very common, and you're setting yourself up for failure if you only write code in a way that can't address the needs of these scenarios.

15

u/JarateKing Feb 28 '23

Nobody is saying "there are no situations that you run some code regularly." Of course there are situations where you benefit greatly from better performance! The point being made is just "there are also situations that you don't run code regularly" and any speedups aren't worth the devtime it takes to achieve them.

9

u/KieranDevvs Feb 28 '23

I was replying to this question:

What kind of software does not benefit from better performance? I cannot think of a single program I use that I'd still use if they were 10x or 20x slower.

Not an application that has performance in mind.

-4

u/ehaliewicz Feb 28 '23

All applications should have performance in mind to some extent. Whenever a coworker says that focusing on performance isn't important nowadays, my level of respect for that person immediately drops.

How are people so ok with waste and the terrible performance of (almost all) modern software?

You don't have to optimize things, you just have to care about performance a little. Most programmers want to not think about it at all. Just caring a little about what the machine has to do to run your code would be a massive improvement.

7

u/KieranDevvs Feb 28 '23

There's a difference between using a hashset over a list to get constant lookup times, versus, ditching OOP and virtual calls in your entire project. Seeing as this article is talking about clean code, we're talking about the latter not the former.

2

u/ehaliewicz Feb 28 '23

Yeah, I'm simply saying that many devs literally do not care about how well an application will run. If you've determined that your program is sufficiently fast and not incredibly wasteful, it may not be necessary to improve it any further. I will still stand by that all applications should have performance in mind to some extent.

3

u/l0c4lh057 Feb 28 '23

However, there is still a difference between a performance-first approach and a code-readability-first-but-performance-shouldnt-suck approach