Please Cc any replies; I am not subscribed.
While working on an implementation of the fannkuch benchmark for the=20
Computer Language Shootout, I discovered that copy-seq runs very slowly=20
for at least some simple vectors. I wrote the following small benchmark:
(proclaim '(optimize (speed 3)
(safety 0) (debug 0) (space 0) (compilation-speed 0)))
(defun copy-simple-vector (vec)
(declare (type simple-vector vec))
(let ((n (length vec)))
(loop for i fixnum from 0 below n
with newvec =3D (make-array (list n))
do (setf (aref newvec i) (aref vec i))
finally (return newvec))))
(defun work (fun vec)
(declare (function fun) (simple-vector vec))
(dotimes (i 1000000)
(funcall fun (copy-simple-vector vec))))
(work (lambda (vec) (declare (ignore vec)))
#(0 1 2 3 4 5 6 7 8 9))
Replacing the call to copy-simple-vector by one to copy-seq makes the=20
program run significantly slower (about a factor five on my ppc machine=20
with sbcl 0.8.18, about a factor 10 on a friend's x86 machine with a=20
recent version of sbcl). Profiling reveals that copy-seq makes a lot of=20
calls to SB-KERNEL:HAIRY-DATA-VECTOR-SET,=20
SB-KERNEL:HAIRY-DATA-VECTOR-REF, ARRAY-DIMENSION, and ARRAY-RANK.
It seems to me that perhaps an optimization could be added that makes=20
copy-seq more efficient for simple-vector arguments.
If you want the best seat in the house, you'll have to move the cat.