[comp.lang.misc] Optimisation

nick@lfcs.ed.ac.uk (Nick Rothwell) (02/10/90)

In article <5453:23:28:32@stealth.acf.nyu.edu>, brnstnd@stealth writes:
>In article <2115@castle.ed.ac.uk> nick@lfcs.ed.ac.uk (Nick Rothwell) writes:
>> In article <838.18:06:33@stealth.acf.nyu.edu>, brnstnd@stealth writes:
>> >... If you care about ``information hiding''
>> >and the ``purity'' of your code more than efficiency, you can't expect
>> >fast code. If you can't bear to put your original code in comments and
>> >write an efficient version with temporary variables, you don't deserve
>> >fast code.
>> 
>> This is rubbish, check out the performance of New Jersey ML
>> (high-level functional language, efficient optimised native code
>> generation).
>
>Are you saying that your compiler is smarter than you are or just that
>it's not as lazy?

I think the original posting was relating essentially "global" or
structural optimisations of entire programs. However, I was really
taking exception to the blanket statement about "information hiding"
and "purity" being at odds with fast code.

>Can it figure out, say, Knuth's algorithm for computing the delta2 table
>in Boyer-Moore string searching, starting from a dumb algorithm for the
>same job?

No, it can't take a slow algorithm and turn it into a fast one. That
is still in the domain of the programmer. What a decent modern
compiler can do is support abstraction, information hiding, "purity"
of code (such as use of user-defined pure functions and arbitrary
local variables) and make it faster than I could do, since this kind
of optimisation (tail-recursion, eta/beta reduction and so on) is
complex and tedious but purely mechanical. I chose New Jersey ML as an
example because (i) ML is a very high level polymorphically typed
functional language, with the features you mentioned, and (ii) the
compiler generates excellent optimised code, on a par with the best C,
Pascal and the like.

>Humans can optimize better than computers. This will be true for a long
>time. I chose the above example randomly, but it'll serve well enough as
>a goal that I won't live to see computers reach.

Optimising algorithms, yes, agreed. Optimising the compilation/code
generation of programs, I don't think so.

>---Dan

		Nick.
--
Nick Rothwell,	Laboratory for Foundations of Computer Science, Edinburgh.
		nick@lfcs.ed.ac.uk    <Atlantic Ocean>!mcvax!ukc!lfcs!nick
~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~
		       ...als das Kind, Kind war...