[erlang-questions] At what point am I "playing compiler"

John Haugeland stonecypher@REDACTED
Tue May 19 01:03:50 CEST 2009


> Knuth also wrote (though I can't find the reference) that it was not
> worth optimising
> something that got called less that 10^9 times (I think that's right)
> - he wrote that something like 20 years ago, so today the advice must
> be 10^12 times :-)

This isn't, of course, meant to be taken literally, if you read the
surrounding text; therefore any attempt to mutate it based on numeric
observations regarding the progress of time is doomed to fail.  And,
of course, the nature of 10^9 hasn't changed; what Knuth was
glad-handing was the scale of difference between an optimized and an
unoptimized behavior, and that hasn't changed as computers have gotten
faster.  To infer that because computers have gotten faster this ratio
has changed is to fail on grounds of losing track of your units of
measurement.

The germane issue here is actually whether optimization saves enough
time to be worth it.  I can give you an extreme counterexample: making
simple changes to my NetFlix Prize approach resulted, without
algorithmic replacement, in several orders of magnitude improvement in
speed; if I hadn't made those optimizations six months ago on an
algorithm that ran only once, it would still be running today, rather
than having completed in a matter of days.

This is a bit like quoting e=mc^2 : there are actually a bunch of
things removed from that in order to make it brief and pithy enough to
use as a rule of thumb.  As soon as you attach to the brevend
pithified version as a literal measurement, you lose track of the
judgement calls you're being reminded to make in favor of arbitrary
magic numbers with no scientific backing; it is the programmer's
equivalent of religion, and if that isn't offensive enough, please
remember that it leads to things like Java.

We're scientists.  We don't pick numbers like 10^9 out of the air.
Knuth, hallowed be his name, was merely giving the range as an
observation to prevent people from sweating single cycles out of their
bash scripts.  Constructing valid counterexamples is trivial for a
college freshman.

Skepticism in all things is the basis of deep understanding.



More information about the erlang-questions mailing list