Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!rpi!turing.cs.rpi.edu!harrisr From: harrisr@turing.cs.rpi.edu (Richard Harris) Newsgroups: comp.lang.lisp Subject: Re: CLOS speed Message-ID: <1989Oct27.224758.13427@rpi.edu> Date: 27 Oct 89 22:47:58 GMT References: <18769@pasteur.Berkeley.EDU> <31037@news.Think.COM> <31074@news.Think.COM> Reply-To: harrisr@turing.cs.rpi.edu (Richard Harris) Organization: RPI CS Dept. Lines: 52 In article <31074@news.Think.COM> barmar@kulla (Barry Margolin) writes: >In article mujica@ra.cs.ucla.edu (S. Mujica) writes: >>What about setting the value of a slot? I have noticed that running >>PCL on Lucid 3.0, it takes about 30 times longer to set the value of >>a slot than to set the value of local variable. > >Accessing a local variable is probably the fastest single operation in any >Lisp implementation. CLOS slots should be compared with DEFSTRUCT slots, >not with local variables. > >I'm sure it will still be much slower in PCL, but that's because it does no >optimization. PCL's simplistic implementation of SLOT-VALUE makes a number >of function calls; (SLOT-VALUE object 'slot) calls (SLOT-VALUE-USING-CLASS >(CLASS-OF object) object 'slot), which has to do some table lookup to >figure out where that slot is in that class. This is wrong. Calls to SLOT-VALUE within the body of a DEFMETHOD are optimized. Look at EXPAND-DEFMETHOD-INTERNAL (in boot.lisp). > >In a high performance implementation, with type declarations and block >compilation, the offset can be determined at compile time, and most of the >above can be compiled away or inlined. The offset can be determined at compile time if: 1) the class of the object is known at compile time, and 2) the metaclass and superclass chains of the object's class can also be determined at compile time, and 3) the class structure uses single inheritance, and 4) the instance variables of the class and its superclasses will not change. PCL generates (reasonably) good code when the class of the object is known at compile time, but PCL can not assume that conditions (3) or (4) are true (when the object's metaclass is standard-class). There may be better slot accessing techniques that could be used for CLOS: for instance, when the Flavors system can determine the class of an object, it arranges to compute at load time an offset into a vector (which is stored in each instance) of offsets into the instance. This is probably the fastest method of slot access that CLOS could use (2 vector accesses per slot-value form), but it has has a significant drawback: it is hard (or impossible) to do load-time evalutation of constants (in code created by macros) in some implementations of CL, because CL does not support load-time constants very well (#, is too limited). > ... > >Barry Margolin, Thinking Machines Corp. > >barmar@think.com >{uunet,harvard}!think!barmar Rick Harris