4 ms·
The problem comes from dynamism. Accessors to class slots are generic functions, and in current implementations cannot be inlined in general, as new methods ca
by pfdietz 3y ago
The problem comes from dynamism. Accessors to class slots are generic functions, and in current implementations cannot be inlined in general, as new methods can be added to them, even if the class of the argument is known statically. Even direct access to slots suffers from the effects of dynamism, since classes can be redefined at any time and the slots moved around.
So, what's needed is a general way to get efficient code for such things even in the face of dynamic redefinition. This is possible, using generated code snippets that are relinked into code when definitions change, but I don't know of any Common Lisp compiler that currently does this.
- dreamcompiler 3y agoAFAIK most of the current CL compilers memoize dynamic dispatch as well as slot vector lookup. They clear these caches if a relevant class or method gets redefined. Of course this precludes the use of some MOP functions like slot-value-using-class; if you use those the system won't cache the slot lookup mechanism.
- pfdietz 3y agoYes, implementations will do what they can, but none of that can be as fast as a simple structure field access when the type of the structure is known at compile time. That compiles to a single instruction.