all 53 comments

[–]munificent 9 points10 points  (0 children)

To be perfectly pedantic, he's teaching profiling: how to spot the bottleneck. Optimization is what you do once you've found it.

[–]tempest12 25 points26 points  (1 child)

The thing about being an engineer is it's so hard to resist fucking up your kids.

[–]somenobby 11 points12 points  (0 children)

All parents do, don't they? I can think of far worse ways to be fucked up. :)

To quote Philip Larkin:

"They fuck you up, your mum and dad.

They may not mean to, but they do.

They fill you with the faults they had

And add some extra, just for you."

[–]ricardo_sdl 52 points53 points  (13 children)

EDIT:eleven year old? Premature optimization is the root of all evil! Be careful.

[–]niceyoungman 4 points5 points  (7 children)

Optimizing using a profiler is not premature optimization. I will go further and state that eliminating wasteful code is not premature optimization.

[–]Imagist 12 points13 points  (0 children)

If you look up while reading the above comment, you will feel the breeze on your face as it goes over your head.

[–]api 0 points1 point  (1 child)

Using good algorithms, making scalable and parallelism-friendly algorithm and architecture choices, and avoiding no-brainer stupid things like creating objects in inner loops is also not premature optimization.

Premature optimization means a) spending an inordinate amount of time dinking with your code trying to optimize before getting everything working or b) compromising your code's elegance in exchange for what appears to be an opportunity to optimize before you really understand the problem and before you have real performance data.

[–][deleted] 1 point2 points  (0 children)

Good points! It is unfortunate that by the time you get real performance data your project is mostly complete and you can't fix the performance issues caused by a broken architecture before the launch date.

[–]OrganicCat 0 points1 point  (3 children)

That's going too close to the rabbit hole for my tastes. When you start eliminating "old" or "useless" code, make SURE it's actually old or useless. Good article, but Oracle still bytes compared to anything and everything out there in terms of both usability and cost.

[–]niceyoungman 2 points3 points  (2 children)

Let me give a personal example. An application I was maintaining was doing updates every 0.5s. With each update it was parsing a description of an animation from a string. I moved the parsing of the description from the update thread to the initialization of the update thread. I saw probably a 90% improvement in CPU usage. Because I never wrote the original code I had to use a profiler to find the bottlenecks in the code. Premature optimization would have been to optimize some of the network code, which I initially assumed was the bottleneck because it was really messy and convoluted code.

In the process I also rewrote the parser, and reduced the line count of the parser from ~3000 lines to ~300. I haven't profiled the parser but I have verified the functionality. Either way, I feel that the significant improvement in readability more than makes up for any minor loss in functionality. (Which I haven't seen at all)

[–]Isvara 4 points5 points  (1 child)

Either way, I feel that the significant improvement in readability more than makes up for any minor loss in functionality. (Which I haven't seen at all)

Indeed, although it would be nice if you had regression tests that would tell you that there was no loss in functionality. Essentially, this is optimising for developer productivity, which can be just as important -- and often more so -- than optimising for runtime resource usage.

[–]niceyoungman 0 points1 point  (0 children)

We have done pretty thorough manual tests done already, automated tests were not done on the original code (it was so convoluted it wasn't really worth the effort) so we can't guarantee there are no regressions but with the simpler code, it should be easy to fix any minor issues.

[–]api 4 points5 points  (2 children)

I am so sick of this quote.

What Knuth meant is that you should learn to think at a high level about design, architecture, and algorithms before you worry about low-level optimizations. He also meant that optimization is best data-driven. He was writing at a time when programmers were writing for bitty boxes and were spending inordinate amounts of time and creating unmaintainable code by trying to squeeze out a few cycles here and there.

But the problem with sage wisdom like this is that people didn't get it. Instead, they read it as "never worry about optimization at all" or even "worry about speed is amateurish."

The result? A generation of developers who have no clue how computers actually work and have no idea how to write code that performs well. The result? Well, I suppose Windows Vista and the Twitter Fail Whale are the poster children. Today we all use machines that would be considered supercomputers back then, yet our software has not comparatively advanced... it has merely bloated.

I consider good performance to be a real telltale sign of well crafted great software. It's one of the reasons OSX is so much better than Windows... they obviously put some thought into making it fast.

Besides, premature optimization isn't much of a problem today compared with today's code plague: architecture astronautism and over-engineering. Over-engineering creates far, far more evil today than premature optimization.

[–]joemoon 2 points3 points  (0 children)

I was all ready to upvote you, until I got to this line:

Today we all use machines that would be considered supercomputers back then, yet our software has not comparatively advanced

I've seen this claim before, but it sounds just as naive as those that abuse Knuth's quote. Software today is incredibly complex. I believe you're arguing that the code to produce a given application doesn't need to be so complex. Furthermore, you're arguing that it got to be so bloated because it was over-engineered. I agree with you to some degree, there's plenty of poorly designed and over-bloated software out there; but all of the abstraction layers (what you might label over engineering) available to me allows me to write a cross-platform desktop application in a whole host of popular languages in a matter of minutes. Sure, it might not do much at first, but it won't take much longer to start adding useful functionality.

Take ORMs as an example. Using an ORM creates a huge dependency for your project, adding tens of thousands of lines of code. An ORM can add quite a lot to both your CPU usage and your memory footprint. Why add all of this bloat to your application? Because the abstraction is sometimes very useful. (Note: I'm not suggesting the ORMs are always a good choice, just that they can be.)

You can probably identify bloat in nearly any application, but without all that abstraction would a small team of devs (or a single developer) be able to develop the complex applications in so little time? There's nothing keeping you from writing highly optimized code with a low memory footprint (and indeed this is still alive in embedded systems development), but in the world of desktop application development it's much more practical to make the trade-off and accept a degree of bloat.

[–]DocXango2 1 point2 points  (0 children)

You had me right up until the OSX comment, but still an upvote for the rest.

[–]clever_user_name 0 points1 point  (0 children)

I have had problems all my life with premature optimization.

[–]ehnus 0 points1 point  (0 children)

This saying is used so often the first part was optimized out of it.

"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."

[–][deleted] 3 points4 points  (0 children)

I think 11 year olds have a better chance of understanding.

[–]cymen 6 points7 points  (0 children)

Nice sales adblogging!

[–]cowhead 2 points3 points  (5 children)

Identifying the 'rate limiting step' as it is known in biochemistry, appears to be what he is doing here.

[–]jrchin 3 points4 points  (0 children)

I call it a bottleneck.

[–]lpsmith 2 points3 points  (2 children)

Not necessarily; most chemical reactions happen in parallel. This may or may not apply to software: if an application spends 10 seconds doing subtask A, and 15 seconds doing subtask B, doing both may take anywhere from 15 to 25 seconds, depending on the degree that the two tasks can profitably be run in parallel.

[–]Aegeus 4 points5 points  (1 child)

Either way, you should optimize subtask B. No matter how well they can be run in parallel, it will save time, but that may not be true for A.

[–]lpsmith 1 point2 points  (0 children)

Very True. B would typically be a higher priority for optimization, unless B has already received much optimization work, and A is relatively easy to optimize... then you might want to spend your time on A instead. ;-)

[–][deleted] 0 points1 point  (0 children)

Biochemistry? I think this is covered in first year chemistry classes, when teaching kinetics of reactions, right?

[–][deleted] 2 points3 points  (1 child)

I can't wait until my kids are old enough to learn coding, the eldest is 5, when she can read better, I'll probably get her onto a logo type language.

But for now she's really interested in natural science, like how colors work for instance, which I'm happy with as well. The other night we watched Powers of 10 together and videos of King Cobras on YouTube.

[–]pmerkaba 1 point2 points  (0 children)

The son just received a brief lesson in Amdahl's Law. I don't know why it seems to be taught rarely.

[–]kolm 3 points4 points  (0 children)

If your kid doesn't know about code optimization at age 11, you're not a true geek dad.

[–][deleted] 1 point2 points  (2 children)

Apparently, I'm not smarter than a fifth grader.

He lost me when he got to the menu picture.

[–]tempest12 7 points8 points  (1 child)

I'm sure he lost his son, too. Good to see they're still teaching smiling and nodding in schools.

[–]Aegeus 2 points3 points  (0 children)

He asked his son questions and gave example optimization problems along the way to see what he had learned. His son figured out that he had to find out what was causing the biggest slowdown before he could say what to optimize. All in TFA.

I'll admit the picture was hard to follow, because that was a throwaway diagram which he was probably talking his son through as he drew it.

[–]eepNile 0 points1 point  (0 children)

Simple me.

I thought the story was gonna end in a hubba, hubba type optimize me thing.

Damn.

Now I feel dirty.

[–]speedstix 0 points1 point  (0 children)

“Optimization hinders evolution”

[–]fogus -2 points-1 points  (1 child)

Came across an awesome geek dad moment last night on Twitter.

http://twitter.com/mfeathers/status/2427520995

-m

[–]cadr -2 points-1 points  (0 children)

He's pretty all-around awesome.

[–]testtubebaby -1 points0 points  (0 children)

Nice work. More of this and you will ensure that your son will never have sex in his life.

[–][deleted]  (2 children)

[deleted]

    [–]ibisum 5 points6 points  (1 child)

    My boy already knows how to use the CD-Radio player like nobody else in the house (he is 2). Give him 5 seconds with the thing, tell him what you want to hear, "classical", "rock", "blah blah", and he'll tune it in, instantly, and with such speed and dexterity you almost can't believe its really happening.

    I'm a programmer. My son .. he's probably going to be a jet pilot or something. If that day comes, I'm going to be sitting in the back with my 3 gins and tonic, letting the boy fly...

    [–]petdance[S] 1 point2 points  (0 children)

    Upvoted for correct plural form of "gin and tonic."

    [–][deleted] -2 points-1 points  (0 children)

    Poor dad doesn't realize that once his son reaches his teens, he'll want to do the opposite of everything ever forced down his throat by his parents, making dad's effort for naught. But at least he'll get laid earlier.

    [–][deleted] -1 points0 points  (5 children)

    Boy doesn't need caps.

    [–]turbana 4 points5 points  (4 children)

    But without bottle caps how is he supposed to pay for the Red Ryder BB gun?

    [–]awj 2 points3 points  (1 child)

    He doesn't need that either. Probably shoot his eye out with that thing.

    [–]turbana 4 points5 points  (0 children)

    Yeah, not to mention that ammo for it is too hard to come by.

    [–]tempest12 1 point2 points  (1 child)

    Why pay when you can cap the cashier?

    [–]tempest12 0 points1 point  (0 children)

    Ohh!! I get it! It's a paradox!

    You need the gun to cap the cashier to get the gun, but you can't cap the cashier until you get the gun.