[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Singleton, default DEFMETHOD now as fast as a DEFUN?



    Date: Thu, 13 Jul 89 08:39 CDT
    From: ihlpf!lgm@att.att.com

    1) Did I find a rather special case, or is it generally true now
    that a DEFUN can be replaced by the corresponding DEFMETHOD without
    loss of speed?

PCL has always provided the optimization that a generic function with
only default methods would be as fast as a function.  In some ports of
PCL it is a little slower, but this could be fixed in the port-specific
code.

    2) What do people think of a style of programming in which one *always*
    uses DEFMETHOD instead of DEFUN, thereby making *all* user-programmed
    behavior specializable?  If a default DEFMETHOD such as the example above
    is as fast as a DEFUN, performance does not suffer unless/until one
    actually *uses* the flexibility (i.e., by writing another method for
    the same generic function).

There seems to be debate about this.  One counter argument is that by
making something a function, you are explicitly stating that it
shouldn't and will not be specialized.  This statement may have some
value in certain programming situations.

    3) One could imagine still another optimization.  If a generic function
    has only one method but that method does have specializers, PCL could
    simply perform quick type checks (in the style of CHECK-TYPE) and,
    if they pass, jump to the one method.

PCL already does this.

    4) If singleton, default DEFMETHODs are now as fast as DEFUNs,
    might one hope that the prohibition on specializing built-in Lisp
    functions might someday be lifted, at least to a limited degree?

One of the issues here is that many of those functions actually get
compiled inline by the compiler (e.g. CAR).  So, some people believe
that turning them into generic functions might require compiling them
as real function calls and that would cause a performance penalty.

I think the real issue is that there hasn't been enough experience with
what happens if you do this in Lisp, and so we weren't ready to try and
standardize something here.  I expect that in the next couple of years,
a number of the Lisp vendors will themselves extend the set of standard
functions that are generic.
-------