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

Re: Efficiency of local fns and closures



  To: GODDEN%gmr.com@relay.cs.net
  cc: slug@warbucks.ai.sri.com
  Subject: Re: Efficiency of local fns and closures 
  Date: Fri, 20 Oct 89 00:05:05 EST
  From: bouma@cs.purdue.edu
  
  
       Consider:
  
       a) In general, are local functions any slower w.r.t. a global fn definit
  no
          I.e. is there any reason to expect BAR to run faster if it were defin
  no
       b) Does the presence of the lexically-apparent free reference to 'y'
  no
          If free ocurrence of 'y' slows down BAR, can that be avoided by
  no

>From my experience, accesses to free references do take longer than
lexical ones.  (And accessing instance variables take even longer.)
However, passing Y as an argument also takes time because it must be
stacked before BAR is called.  References to it will be faster
however.  You have to experiment with your application by careful
timing and disassembling.

Also, funcalling a closure takes slightly longer then calling a function
because the environment must be stacked.

       c) I have read that closures cannot be compiled.  True? False?
  
  I'd start reading something else.

It is currently true (7.2) that if you do something like

(let ((count 0))
  (defun foo ()
   (incf count)))

at the top level, the body of FOO is not compiled.  Plus you get grief
about it from the compiler.

However, other uses fo closures are compiled.  With proper
declarations  like (DECLARE SYS:DOWNWARD-FUNARG)
you can also avoid consing them.