Newsgroups: comp.lang.lisp Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!hellgate.utah.edu!defun.utah.edu!sandra From: sandra%defun.utah.edu@cs.utah.edu (Sandra J Loosemore) Subject: Re: Linking and MACL (really efficiency of local functions) Date: 22 Nov 89 08:22:00 MST Message-ID: <1989Nov22.082200.3230@hellgate.utah.edu> Organization: PASS Research Group References: <21316@brunix.UUCP> <1989Nov20.150510.20700@hellgate.utah.edu> In article simon@bear.UUCP (Simon Leinen) writes: >With many compilers, using local functions is always *slower* than >separate functions. Perhaps this is what prevents so many people from >using LABELS and FLET. I'm getting tired of seeing LABELS and FLET slandered where the blame really rests on lousy implementation of these constructs in some compilers. Depending on how you implement symbols and functions, calling a globally named function generally requires an indirection through the symbol object to access its symbol-function component. That requires at least one and maybe more memory references to get the address of the code for the function. On the other hand, the easiest way to implement locally named functions is to treat them just like local variables. Some compilers will keep these in registers whenever possible, so that there is no need to reference memory to get the address of the function. In the case of non-closed functions, the address of the code for the called function can be computed as a load-time constant and patched directly into the code for the caller. Once you have the address of the function in hand, the overhead of calling it is the same no matter whether it is named locally or globally or not at all. I suspect that in most implementations, the cost of computing the function address is very small compared to all the other work involved in setting up the call (such as moving arguments to the right places) anyway. Calling a closure can involve extra overhead in some implementations (again, this varies) but whether or not a function is closed is again independent of how it is named. Creating a closure is usually even slower, but there is no reason for it to be any slower for FLET and LABELS than it is for anonymous lambdas. -Sandra Loosemore (sandra@cs.utah.edu)