Martin Cracauer wrote:
>
> Return of double-floats is very costly (the compiler should have
> printed a note informing you of the problem, if not you need to switch
> on notes).
>
> Try not to let the double-float "escape" to global variables or as
> function returns or as direct function parameters.
>
> If needed, use an array or a struct to pass it around functions by
> reference.
>
> One of the uglier sides of real existing Lisp systems...
>
> Martin
>
>
I also have some double-float intensive code which gives me problems
whenever I do something like this:
(declaim (optimize (speed 3) (safety 0)))
(defvar *result* nil)
(defstruct vec3
(x 0.0d0 :type double-float)
(y 0.0d0 :type double-float)
(z 0.0d0 :type double-float))
(defun newvec (v)
(declare (vec3 v))
(make-vec3 :x (* (vec3-x v) 0.999999d0)
:y (* (vec3-y v) 0.999999d0)
:z (* (vec3-z v) 0.999999d0)))
(defun test-1 ()
(let ((v (make-vec3)))
(dotimes (i 300000)
(setf *result* (newvec v)))))
(time (test-1))
Evaluation took:
0.16 seconds of real time
0.1 seconds of user run time
0.06 seconds of system run time
[Run times include 0.04 seconds GC run time]
0 page faults and
28794864 bytes consed.
Compiling with Notes gives me messages such as:
In: DEFSTRUCT VEC3
(DEFSTRUCT VEC3
(X 0.0d0 :TYPE DOUBLE-FLOAT)
(Y 0.0d0 :TYPE DOUBLE-FLOAT)
(Z 0.0d0 :TYPE DOUBLE-FLOAT))
Note: Doing float to pointer coercion (cost 13) to "<return value>".
Compiling DEFUN NEWVEC:
File: /home/jonathan/coding/lisp/eff2.lsp
In: DEFUN NEWVEC
(MAKE-VEC3 :X (* (VEC3-X V) 0.999999d0) :Y (* (VEC3-Y V) 0.999999d0) ...)
Note: Doing float to pointer coercion (cost 13).
[Last message occurs 3 times]
How do I avoid boxing all those double floats in my make-vec3 call? Am
I going to have trouble any time I return a double-float with #'*?
Thanks,
Jonathan