Next: , Previous: , Up: CLOS   [Contents][Index]


2.23.4 Inlining Methods in Effective Methods

When a generic function is called, an effective method is constructed from applicable methods. The effective method is called with the original arguments, and itself calls applicable methods according to the generic function’s method combination. Some of the function call overhead in effective methods can be removed by inlining methods in effective methods, at the expense of increased code size.

Inlining of methods is controlled by the usual inline declaration. In the following example, both foo methods shown will be inlined in effective methods:

(declaim (inline (method foo (foo))
                 (method foo :before (foo))))
(defmethod foo ((x foo)) ...)
(defmethod foo :before ((x foo)) ...)

Please note that this form of inlining has no noticeable effect for effective methods that consist of a primary method only, which doesn’t have keyword arguments. In such cases, PCL uses the primary method directly for the effective method.

When the definition of an inlined method is changed, effective methods are not automatically updated to reflect the change. This is just as it is when inlining normal functions. Different from the normal case is that users do not have direct access to effective methods, as it would be the case when a function is inlined somewhere else. Because of this, the function pcl:flush-emf-cache is provided for forcing such an update of effective methods.

Function: pcl:flush-emf-cache &optional gf

Flush cached effective method functions. If gf is supplied, it should be a generic function metaobject or the name of a generic function, and this function flushes all cached effective methods for the given generic function. If gf is not supplied, all cached effective methods are flushed.

Variable: pcl::*inline-methods-in-emfs*

If true, the default, perform method inlining as described above. If false, don’t.


Next: Effective Method Precomputation, Previous: Slot Access Optimization, Up: CLOS   [Contents][Index]