[cffi-devel] Strange Performance Issue

Mikael Lax mikael.lax at bredband.net
Mon Sep 3 13:22:19 UTC 2007


Hello,

I was working on a cl-opengl app recently and I noticed that my textures were taking much longer to load than I could remember. After some investigation I could distill the following test functions:

(defun test-1 ()
  (let* ((array (make-sequence 'vector (* 512 512 3) :initial-element 0))
	 (count (length array)))
    (cffi:with-foreign-object (data 'cl-opengl-bindings:ubyte count)
      (loop for i below count
	 do
	   (setf (cffi:mem-aref data 'cl-opengl-bindings:ubyte i) (aref array i))))))

(defun test-2 ()
  (let* ((array (make-sequence 'vector (* 512 512 3) :initial-element 0))
	 (count (length array))
	 (type (cl-opengl::symbolic-type->real-type :unsigned-byte)))
    (cffi:with-foreign-object (data type count)
      (loop for i below count
	 do
	   (setf (cffi:mem-aref data type i) (aref array i))))))


Now observe the timings (in SBCL) for them:

* (time (test-1))
Evaluation took:
  0.027 seconds of real time
  0.019999 seconds of user run time
  0.006666 seconds of system run time
  0 calls to %EVAL
  0 page faults and
  3,145,736 bytes consed.
NIL

* (time (test-2))
Evaluation took:
  9.565 seconds of real time
  8.629437 seconds of user run time
  0.236652 seconds of system run time
  [Run times include 0.74 seconds GC run time.]
  0 calls to %EVAL
  0 page faults and
  688,918,576 bytes consed.

A substantial difference is apparent.
For completeness I also tried CLISP:

[14]> (time (test-1))
Real time: 10.952836 sec.
Run time: 10.169337 sec.
Space: 173015440 Bytes
GC: 100, GC time: 0.816611 sec.
NIL
[15]> (time (test-2))
Real time: 18.55567 sec.
Run time: 17.215544 sec.
Space: 342884976 Bytes
GC: 199, GC time: 1.526577 sec.
NIL

While not as prominent, a difference is still clearly visible. Now I'm curious as to why there's such a performance difference here, am I missing something obvious? Does it happen to anyone else?

Sincerely,
Mikael Lax

PS: I don't know if this or cl-opengl is the appropriate mailing-list for this, but since there seems to be some cross-pollination of cl-opengl/cffi developers I'm sending it here on a gamble.



More information about the cffi-devel mailing list