When operating on values that have non-descriptor representations
(see non-descriptor), 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
Inefficient representation coercions may be due to type uncertainty, as in this example:
(defun set-flo (x) (declare (single-float x)) (prog ((var 0.0)) (setq var (gorp)) (setq var x) (return var)))
which produces this efficiency note:
In: DEFUN SET-FLO (SETQ VAR X) Note: Doing float to pointer coercion (cost 13) from X to VAR.
var is not known to always hold values of type
single-float, so a descriptor representation must be used for its value.
In this sort of situation, adding a declaration will eliminate the inefficiency.
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 block-compilation, numeric-types and profiling.
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:
(defun cf+ (x y) (declare (single-float x y)) (cons (+ x y) t))
which gives this efficiency note:
In: DEFUN CF+ (CONS (+ X Y) T) Note: Doing float to pointer coercion (cost 13), for: The first argument of CONS.
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:
(defun if-cf+ (x y) (declare (single-float x y)) (cons (if (grue) (+ x y) (snoc)) t))
produces this note:
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:
(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.
Note that the return value of a function is also a place to which coercions may have to be done:
(DEFUN F+ (X Y) (DECLARE (SINGLE-FLOAT X Y)) (+ X Y)) Note: Doing float to pointer coercion (cost 13) to "<return value>".
Sometimes the compiler is unable to determine a name for the source or destination, in which case the source context is the only clue.