在以下程序中,删除该行
(declare (type (simple-array bit) arr))
使用 SBCL 使运行时间增加了 3 倍以上。另一方面,defclass宏 via中给出的类型信息似乎对性能没有影响。:type
(defclass class-1 () ((arr :type (simple-array bit))))
(defun sample (inst)
(declare (type class-1 inst))
(let ((arr (slot-value inst 'arr)))
(declare (type (simple-array bit) arr)) ;; 3x running time without
(map-into arr #'(lambda (dummy) (if (< (random 1.0) 0.5) 0 1)) arr)))
(let ((inst (make-instance 'class-1)))
(setf (slot-value inst 'arr) (make-array 10000 :element-type 'bit))
(loop for i from 1 to 10000 do (sample inst)))
我怎样才能获得相同的性能优势,而不必在每次使用时都声明arr插槽 a ?simple-array bit后者特别烦人,因为(据我所知)let每次都需要通过或类似方式引入绑定;我不能只写(slot-value inst 'arr)在我需要的地方。