When operating on values that have non-descriptor representations (see section 5.11.2), there can be a substantial time and consing penalty for converting to and from descriptor representations. For this reason, the compiler gives an efficiency note whenever it is forced to do a representation coercion more expensive than *efficiency-note-cost-threshold* (page ).
Inefficient representation coercions may be due to type uncertainty, as in this example:
which produces this efficiency note:(defun set-flo (x) (declare (single-float x)) (prog ((var 0.0)) (setq var (gorp)) (setq var x) (return var)))
The variable var is not known to always hold values of type single-float, so a descriptor representation must be used for its value. In sort of situation, and adding a declaration will eliminate the inefficiency.In: DEFUN SET-FLO (SETQ VAR X) Note: Doing float to pointer coercion (cost 13) from X to VAR.
Often inefficient representation conversions are not due to type uncertainty--instead, they result from evaluating a non-descriptor expression in a context that requires a descriptor result:
If such inefficient coercions appear in a ``hot spot'' in the program, data structures redesign or program reorganization may be necessary to improve efficiency. See sections 5.7, 5.11 and 5.14.
Because representation selection is done rather late in compilation, the source context in these efficiency notes is somewhat vague, making interpretation more difficult. This is a fairly straightforward example:
which gives this efficiency note:(defun cf+ (x y) (declare (single-float x y)) (cons (+ x y) t))
The source context form is almost always the form that receives the value being coerced (as it is in the preceding example), but can also be the source form which generates the coerced value. Compiling this example:In: DEFUN CF+ (CONS (+ X Y) T) Note: Doing float to pointer coercion (cost 13), for: The first argument of CONS.
produces this note:(defun if-cf+ (x y) (declare (single-float x y)) (cons (if (grue) (+ x y) (snoc)) t))
In: DEFUN IF-CF+ (+ X Y) Note: Doing float to pointer coercion (cost 13).
In either case, the note's text explanation attempts to include additional information about what locations are the source and destination of the coercion. Here are some example notes:
Note that the return value of a function is also a place to which coercions may have to be done:(IF (GRUE) X (SNOC)) Note: Doing float to pointer coercion (cost 13) from X.(SETQ VAR X) Note: Doing float to pointer coercion (cost 13) from X to VAR.
Sometimes the compiler is unable to determine a name for the source or destination, in which case the source context is the only clue.(DEFUN F+ (X Y) (DECLARE (SINGLE-FLOAT X Y)) (+ X Y)) Note: Doing float to pointer coercion (cost 13) to "<return value>".