Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!think!mintaka!mit-eddie!bu.edu!xylogics!world!paradigm!gjc From: gjc@paradigm.com Newsgroups: comp.lang.lisp Subject: Re: FUNCALL question, fun facts Message-ID: <26@paradigm.com> Date: 29 Jan 90 19:11:35 GMT References: <3277@accuvax.nwu.edu> <1990Jan28.175437.19293@hellgate.utah.edu> Organization: Paradigm Associates Inc, Cambridge MA Lines: 35 There used to be a saying, FUNCALL CONSIDERED HARMFULL.. In article <1990Jan28.175437.19293@hellgate.utah.edu>, sandra%defun.utah.edu@cs.utah.edu (Sandra J Loosemore) writes: > In article <3277@accuvax.nwu.edu> krulwich@ils.nwu.edu (Bruce Krulwich) writes: >>Rough experiments in Lucid CL (on a SPARCstation) indicate that there is >>indeed twice the procedure-call overhead in calling a closure stored in a >>lexically bound variable as in calling a global function (stored in a >>symbol's function slot). > > Many implementations do optimize FUNCALL heavily. It is theoretically > possible to compile FUNCALL to be just as efficient as an ordinary > call to a named global function ... Enough theory, here are some fun-facts-to-know and tell. (1) In the MIT CADR or LMI LAMBDA lispmachine (FUNCALL F X) and (F X) compiled into *exactly* the same machine instructions. (2) The case (FUNCALL F X) where F was a local variable was very slightly, but measurably FASTER than the case of (F X) where F was a "global" (3) Symbolics and then later Texas Instruments improved on the instruction set such that (FUNCALL F X) and (F X) were indeed different, resulting in some extra overhead for the FUNCALL case, although it is very difficult to measure the difference. (4) On a VAX it is quite easy to implement lexical closures in such a way (inline-code trampolines) such that the two cases produce the same instructions. (5) On some RISC architectures, e.g. SPARC from SUN, there is different code produce for {This is C code now, not lisp:} (*F)(X); vs. F(X); and in-fact a little subroutine called POINTERCALL is called in the (*F)(X); case. -GJC (Also known as the John Silber of Lisp Implementors?)