Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornell!travelers.mail.cornell.edu!news.tc.cornell.edu!news.cac.psu.edu!howland.reston.ans.net!news.sprintlink.net!peernews.demon.co.uk!uknet!festival!edcogsci!jeff
From: jeff@aiai.ed.ac.uk (Jeff Dalton)
Subject: Re: case for Lisp
Message-ID: <D3zypz.Hr@cogsci.ed.ac.uk>
Sender: usenet@cogsci.ed.ac.uk (C News Software)
Nntp-Posting-Host: bute-alter.aiai.ed.ac.uk
Organization: AIAI, University of Edinburgh, Scotland
References: <3h91a8$nrc@info-server.bbn.com>
Date: Tue, 14 Feb 1995 15:51:35 GMT
Lines: 50

In article <3h91a8$nrc@info-server.bbn.com> Clint Hyde <chyde@bbn.com> writes:
>In article <3h2n14$164@necco.harvard.edu> pg@hershey.harvard.edu (Paul Graham) writes:

>--> Supplying declarations is not as mysterious or inconvenient as people
>--> think.  Nor as ugly, since you can easily write a macro to insert
>--> declarations into numeric expressions.  I have included such a macro
>--> in the new introduction to Common Lisp that I'm writing now.
>
>my experience (not as extensive as Ken Anderson's) is that declarations
>are not the source of or solution to the problem. or at least the ones
>I've faced...
>
>lousy algorithms are. every time I've had a problem for which I found a
>speedup, it wasn't by using declarations--it was by seriously altering
>the algorithm.
>
>two weeks ago I produced a 3x speedup in the interface between our DB
>and the clients by making an algorithm change. no declarations involved
>at all.
>
>this is not to suggest that decls aren't worthwhile...but I dont' think
>they are the holy grail here.

Algorithms certainly make a difference and often have more scope for
making a large differtence than declarations (e.g. O(n^3) becomes O(n^2)
while declarations tend just to change the factor -- something becomes
k times faster rather than going from, say k(n^3) to k(n^2)).  So
basically I agree with you.  Indeed, all of the usual advice works
just as well for Lisp as it does for other kinds of languages:
look at the algorithms and data structures first, find out where
the program is spending its time, employ low-level tricks only
at the end and where they'll make a difference.  I'm sure you don't
need me to tell you any of this.

However, declarations and other low-level "micro-optimization" should
not be overlooked.  They _can_ make a significant difference (small
integer factors rather than, say, 20%).  I have seen this on a number
of occasions.

Putting declarations everywhere may not help you and may even make
things worse, so you need to have some idea of where declarations will
make a difference.

For instance, in Common Lisp, addition of two double-precision floats
will typically be a procedure call, and the procedure will do something
like a double case statement to figure out that it's double + double
rather than, say, bignum + ratio.  A declaration can get all that
replaced by a single instruction.  

-- jeff
