defcvar access is much slower on SBCL than it could be

Bug #1560678 reported by Attila Lendvai
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
CFFI
Confirmed
Wishlist
Unassigned

Bug Description

FTR, as reported by Stas on #sbcl:

(cffi:defcvar errno :int)

(defun foo () errno)

(time (loop repeat 1000000 do (foo)))
Evaluation took:
  2.779 seconds of real time
  2.864000 seconds of total run time (2.864000 user, 0.000000 system)
  103.06% CPU
  7,485,939,201 processor cycles
  1 page fault
  239,999,728 bytes consed

(defun foo2 () (sb-alien:extern-alien "errno" sb-alien:int))

(time (loop repeat 1000000 do (foo2)))
Evaluation took:
  0.005 seconds of real time
  0.000000 seconds of total run time (0.000000 user, 0.000000 system)
  0.00% CPU
  11,885,253 processor cycles
  0 bytes consed

Tags: sbcl
Stas Boukarev (stassats)
Changed in cffi:
status: New → Confirmed
Revision history for this message
Luís Oliveira (luismbo) wrote :

The slowdown comes from CFFI using sb-sys:find-foreign-symbol-address whereas your FOO2 version uses the simpler sb-sys:foreign-symbol-sap. Alas, they don't seem to be interchangeable.

description: updated
Revision history for this message
Luís Oliveira (luismbo) wrote :

By /not interchangeable/, I mean the test suite crashes if I replace one by the other. I don't fully remember the details, but it is related to function vs non-function pointers and the linkage table. Stas, do you have any suggestions?

Changed in cffi:
importance: Undecided → Wishlist
tags: added: sbcl
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.