Trust about D programming.

Walter Bright newshound2 at digitalmars.com
Thu Jan 24 17:17:44 PST 2013


On 1/24/2013 8:43 AM, H. S. Teoh wrote:
> I remember being actually offended when I read about premature
> optimization. I felt insulted at the idea that my hand-written code
> could actually underperform what the compiler mechanically produces. Too
> bad it's actually true. :-P
>
> I later learned that my obsession with premature optimization distracted
> me from actually thinking about the algorithms, so that I was spending
> 90% of my time optimizing the last CPU cycles out of an O(N^2) algorithm
> when even a poorly-written O(log N) algorithm would have easily
> outperformed my "optimized" code.
>
> Not to mention the humiliation of discovering, when I actually profiled
> my code, that the hotspots were nowhere near where I thought they were.
> I had spent 90% of my time "optimizing" for a <1% gain, when a simple
> algorithm fix at the real hotspot gained 20% instantly.

Don't feel bad. Everyone goes through that.

Keep in mind that people who are attracted to the dirty job of writing compiler 
back ends tend to be people who are old time assembler hackers, and they know 
the tricks of the trade. Naturally, they wire that knowledge into the compiler.

And they do learn new tricks all the time, and put those in, too.

It's like thinking you can buy a $10 gimmick from the auto parts store and 
increase your gas mileage 10%. Ain't gonna happen, the car makers aren't stupid.



More information about the Digitalmars-d mailing list