Next: Verbosity Control
Up: Efficiency Notes
Previous: Efficiency Notes and Type
  Contents
  Index
Representation Efficiency Notes
representation efficiency notes
for representation
object representation efficiency notes
stack numbers
non-descriptor representations
forcing of
When operating on values that have non-descriptor representations
( see section 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
** (page
)efficiency-note-cost-threshold.
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.
The variable var is not known to always hold values of typesingle-float, so a descriptor representation must be used for its value.
In sort of situation, and 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:
- Assignment to or initialization of any data structure other than
a specialized array ( see section specialized-array-types), or
- Assignment to a special variable, or
- Passing as an argument or returning as a value in any function
call that is not a local call ( see section number-local-call.)
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:
(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.
Next: Verbosity Control
Up: Efficiency Notes
Previous: Efficiency Notes and Type
  Contents
  Index
Peter Van Eynde
2001-03-08