News for hackers. Stuff that matters.
Re:“Clean” Code, Horrible Performance by fvdessen on Tuesday February 28, 2023 @05:33PM (#34975886)
If you program using design patterns that are 10x slower, your application end up 10x slower, even after you've optimised the hot spots away, and the profiler will not give you any idea that it could be still 10x faster.
Re:“Clean” Code, Horrible Performance by rileyphone on Tuesday February 28, 2023 @05:56PM (#34976124)
Not the case if your program is spending most of its time waiting, which is typical these days.
Re:“Clean” Code, Horrible Performance by whstl on Tuesday February 28, 2023 @07:04PM (#34976779)
Not necessarily in the general case. If the program is a single user, locally ran program, then sure. If it's some sort of backend or distributed service, this is just wasted performance that can be used to serve more users. Virtually every distributed service built today is able to take advantage of this.

With a non-pessimal design, not only you are able to pay less money on servers in the long term, you're also able to delay complex scaling strategies. Scaling also costs money.

Not to mention that building something with this kind of overhead also means that a lot developer time was spent in the first place, which is still expensive in our industry.

Re:“Clean” Code, Horrible Performance by Zvez on Wednesday March 01, 2023 @04:42AM (#34980475)
using 'unclean' code practice will increase development costs. And more importantly - maintainability of such code.

>Virtually every distributed service built today is able to take advantage of this

most of built today services can take much more advantage in using better system design practices.

Re:“Clean” Code, Horrible Performance by badsectoracula on Tuesday February 28, 2023 @06:14PM (#34976298)
If your profiler doesn't show any hotspots (which is incredibly rare in practice) and your program is still slow, it means you can simply pick any of whatever functions/methods show up near the top to optimize.

If your program isn't slow then you don't need to bother making it any faster. Even Michael Abrash, who specializes in code optimization, once explicitly wrote in his graphics programming black book that "The objective (not always attained) in creating high-performance software is to make the software able to carry out its appointed tasks so rapidly that it responds instantaneously, as far as the user is concerned. In other words, high-performance code should ideally run so fast that any further improvement in the code would be pointless [..] Notice that the above definition most emphatically does not say anything about making the software as fast as possible".[0]

[0] https://www.jagregory.com/abrash-black-book/#understanding-h...

Re:“Clean” Code, Horrible Performance by saagarjha on Tuesday February 28, 2023 @06:17PM (#34976333)
> If your profiler doesn't show any hotspots (which is incredibly rare in practice) and your program is still slow, it means you can simply pick any of whatever functions/methods show up near the top to optimize.

No, though s/any/many/ would make this true.

Re:“Clean” Code, Horrible Performance by jbverschoor on Tuesday February 28, 2023 @06:59PM (#34976730)
Sure.. but the overall performance is in the cpu/vm, kernel, OS, UI, vm, electron, node, browser, javascript vm. etc etc

There are no hotspots. Computing has become lukewarm by default, and just like the globe, it's slowly heating up.

Re:“Clean” Code, Horrible Performance by fvdessen on Tuesday February 28, 2023 @09:55PM (#34978201)
Think of using slow patterns as using a slow programming language. After you've optimised your python program and eliminated all hotspots, the python profiler isn't going to say 'hey, this could be still 10x faster if rewritten in go'. Note that if you write a graphics engine, you aren't going to use python or even go, but something more like c, c++, rust, even though your code would be cleaner in python. Clean code techniques elevate your level of abstraction and prevent some problems, but at the (significant) cost of performance. It's of course always a matter of trade-offs and this matters more or less depending on which problem you are trying to solve.
Re:“Clean” Code, Horrible Performance by DeathArrow on Wednesday March 01, 2023 @03:48AM (#34980173)
>Clean code techniques elevate your level of abstraction and prevent some problems

What problems do they prevent?

Re:“Clean” Code, Horrible Performance by Applejinx on Wednesday March 01, 2023 @06:47AM (#34981292)
Unemployment :)

If you're able to make a program into a sort of puzzle concealing its state inside a twisty maze of tiny virtual functions so it's impossible to see plainly how anything is done, then you become indispensable as the only one who's internalized how the thing works.

And then you insist it's all for easier comprehension… for those sufficiently intelligent to comprehend it.

Re:“Clean” Code, Horrible Performance by trashtester on Wednesday March 01, 2023 @08:30AM (#34982138)
Even more new clothes for the emperor.
Re:“Clean” Code, Horrible Performance by fvdessen on Wednesday March 01, 2023 @09:03AM (#34982488)
If the average programmer didn’t use ‘clean code’ techniques they would end up with crazy spaghetti, not the fast and clear code shown in the video. (the average programmer is not on HN and can’t do fizzbuzz)
Re:“Clean” Code, Horrible Performance by badsectoracula on Wednesday March 01, 2023 @10:19AM (#34983296)
> After you've optimised your python program and eliminated all hotspots, the python profiler isn't going to say 'hey, this could be still 10x faster if rewritten in go'.

No it wont say something like that but if you profile Python itself and see that a lot of time is spent in Python you can get a hint that rewriting it in another language that doesn't have Python's overhead might help.

Re:“Clean” Code, Horrible Performance by boredhedgehog on Wednesday March 01, 2023 @02:47AM (#34979797)
> If your program isn't slow then you don't need to bother making it any faster.

But you can only judge that for the very limited set of hardware you personally have access to. You might have many users -- or potential users -- with slower CPUs.

Re:“Clean” Code, Horrible Performance by badsectoracula on Wednesday March 01, 2023 @10:15AM (#34983262)
This is where having a target hardware comes in. Aside from doing it for fun, there isn't much of a point to care for 15 year old PCs for example.
Re:“Clean” Code, Horrible Performance by DeathArrow on Wednesday March 01, 2023 @03:46AM (#34980160)
Casey does not advocate for code optimization. Not writing code in a way that is known to degrade performance does not mean you are doing optimization.
Re:“Clean” Code, Horrible Performance by amelius on Wednesday March 01, 2023 @04:58AM (#34980582)
No, if one day you decide to run it on a less capable CPU, it's nice if the optimization work has been done.
Re:“Clean” Code, Horrible Performance by badsectoracula on Wednesday March 01, 2023 @10:17AM (#34983282)
This is the same as trying to guess the future that creates "astronautical architecture". You set a target hardware you're willing to support (e.g. PCs released in the last 10-15 years) and anything less is out of scope of the project. You don't need to support 8086 PCs for example.

(ignoring projects made for fun of course)

Re:“Clean” Code, Horrible Performance by paxys on Tuesday February 28, 2023 @08:00PM (#34977332)
All of the advice in that article isn't going to bring your server latency for an API call down from 1000ms to 30ms, but rather from 30ms to 25ms. So sure, if you absolutely must optimize that 30ms call after you have fixed everything else then go ahead, but very few are at that stage or will ever get to that stage. And if you try to optimize that last 5ms at the expense of the much larger issues then you are actually making things worse.
Re:“Clean” Code, Horrible Performance by dmitriid on Wednesday March 01, 2023 @01:38AM (#34979426)
> All of the advice in that article isn't going to bring your server latency for an API call down from 1000ms to 30ms, but rather from 30ms to 25ms.

Of course it will.

If your backend service is already suboptimal, and running at 10x worse performance, optimizing that will give you, well, a 10x performance boost.

Imagine replacing poor in-memory reimplementation of database queries that most graphql servers do with actual opttimised database queries. And a better code on top.

Boom. You're operating close to the speed of light.

Re:“Clean” Code, Horrible Performance by Zvez on Wednesday March 01, 2023 @04:39AM (#34980458)
>Imagine replacing poor in-memory reimplementation of database queries that most graphql servers do with actual opttimised database queries. And a better code on top.

but you are actually talking about optimizing system design, and not reducing virtual functions calls :).

And that the point of this thread: you need to optimize parts that slow you the most.

So no, in most cases optimizing virtual calls won't bring you from 1s to 30ms

Re:“Clean” Code, Horrible Performance by seadan83 on Wednesday March 01, 2023 @01:23AM (#34979352)
It's rare that its the algorithm and not the design that is slowing you down. Though, sometimes it is the algorithm slowing you down, just usually it's the design.

As an example, I recently worked on a large system that was optimized to do a big data transformation in an efficient way. It turns out that data is transformed back to the original format later downstream. So much for the optimization...

All that is to say, often it is the case that "simple > fast"

Clean code at the time had a lot going forward it, and it was an improvement over a lot of JavaEE code that was written in absolutely procedural ways with less care for the developer reading the classes, functions, or individual statements compared to punching out near assembly-like code and moving on.

Re:“Clean” Code, Horrible Performance by Zvez on Wednesday March 01, 2023 @04:35AM (#34980429)
no take your tupical web service application. Even if you use design patterns that are 10x slower, your program will still be as fast as your DB and overall system architecture. And the choices on your DB schema, indexes and caches will have 100x more effect on your 99pp response time than design pattern you use.
Re:“Clean” Code, Horrible Performance by whstl on Wednesday March 01, 2023 @06:16AM (#34981091)
That's only true if the DB is equally as problematic, and you programming language/framework itself aren't compounding on the overhead caused by the "10x slower" architecture.

On slower languages with slower runtimes, something that is 10x slower than normal code will have much more overhead than in the examples demonstrated by Casey. It won't be about "30ms vs 25ms" as some people are saying. In the past I remember seeing differences between 400ms and 20ms between JBuilder and .to_json in a critical endpoint in a Rails app, to give one example. Sure, one is "cleaner", but in the end it's a 20x overhead that has no place this case.

Also, the myth that "processors spend time waiting for IO" that is spread across this thread is BS. In reality, that's only true for single-user programs. If the app is part of a distributed system, the CPU time can be used to serve more users. This allows you to significantly delay more complex scalability efforts, which is also precious developer (or DevOps) time.

Not to mention that applying "Clean Code" in the first place also takes precious time, which could be used for features or anything making money, even optimizing the DB. Instead, this time is used to mess up the code in ways that have zero proven efficacy, and some developers instead think are terrible.

Re:“Clean” Code, Horrible Performance by WesolyKubeczek on Wednesday March 01, 2023 @07:21AM (#34981555)
If you can remove thinly spread overhead from your web framework or any wasteful ritual dance you make for each request, it might not be much, but it does add up over the course of 24 hours * number of workers to quite a bit.
Re:“Clean” Code, Horrible Performance by trashtester on Wednesday March 01, 2023 @08:34AM (#34982190)
I would argue that persistance and caching strategies are also design patterns. Of course, if you're not the tech lead/architect it may be out of your hands.

If you're working with databases, performance often boils down to minimizing the number of times you have to access the database (over a multi-service stack, not just a single web service).

Re:“Clean” Code, Horrible Performance by gjulianm on Wednesday March 01, 2023 @04:36AM (#34980438)
Well, for starters, Amdahl's law exists. If you use design patterns that are 10x slower on a code path that takes only 0.5% of the execution time your application ends up 0.55% slower. And the profiler never tells you how faster can a code path be. It just tells you where are you spending most of your time so you can put the effort where it matters.
Re:“Clean” Code, Horrible Performance by trashtester on Wednesday March 01, 2023 @08:28AM (#34982118)
This is precisely the kind of situation where it's imperative to consider performance before starting to build a new system.

When you hit Amdahl's law, it's because you (or someone else) has made decisions about the high level design/patterns to use in a system. To remove such bottlenecks, you may have to scrap the entire project and start over.

For the inner loops, it's perfectly fine to leave most of the optimization for later. But for overall design, it needs to be right from the start.

Time and time again, I see devs stuck in some paradigm (often front-end devs or low volumen RESTful microservices) that makes it almost impossible to handle non-trival data volumes or traffic, causing new products to fail.

Re:“Clean” Code, Horrible Performance by gjulianm on Thursday March 02, 2023 @04:27AM (#34993764)
I mean, you always hit Amdahl's law, and the point is that most often the time limits are not that related to the architecture. Let's say you do these "10x slower patterns" in a backend application, in the part where the DB model gets translated to a response to give the client... Yeah, maybe that pattern is slower but most of the time of the response is spent on the network and the DB response.

I do agree that overall design needs to fit performance requirements but for the most part that has nothing to do with "clean code" patterns.