[Ecls-list] Speed of indirect calls.
Juan Jose Garcia-Ripoll
juanjose.garciaripoll at googlemail.com
Sat Feb 14 08:25:04 UTC 2009
On Thu, Feb 12, 2009 at 11:52 PM, Juan Jose Garcia-Ripoll
<juanjose.garciaripoll at googlemail.com> wrote:
> On Thu, Feb 12, 2009 at 3:55 AM, Waldek Hebisch
> <hebisch at math.uni.wroc.pl> wrote:
>> However, it looks that such definition is unsafe (because bytecoded
>> functions, closures and CLOS generic functions all use different
>> calling convention even if the argument list is fixed).
>>
>> It would be nice if ECL used uniform calling convention for
>> functions with fixed argument lists making the above optimization
>> safe (even better, ECL could just generate efficient call).
>
> Yes, I agree that calling conventions right now are a bit slow. There
> are some caveats, though, which make the design of new conventions
> difficult.
I have added a new branch to the git repository, called new_gc. This
branch contains experiments I am doing about the calling convention.
Right now results are not very optimistic, with only minor differences
between before and after. I am using the code below. The goal would be
to have to function pointers in the function objects, one for calling
with a fixed # of arguments, one for not.
Juanjo
;; new_cfun (time (do_it 1000000))
real time : 0.181 secs
run time : 0.177 secs
gc count : 1 times
consed : 5646828 bytes
;; master
real time : 0.186 secs
run time : 0.184 secs
gc count : 1 times
consed : 5543420 bytes
(defmacro SPADCALL (&rest L)
(let ((args (butlast l))
(fn (car (last l)))
(gi (gensym)))
;; (values t) indicates a single return value
`(let ((,gi ,fn))
(the (values t)
(funcall
(the (function ,(make-list (length l) :initial-element t) t)
(car ,gi))
, at args
(cdr ,gi))))))
(defun GETREFV (n) (make-array n :initial-element nil))
(defun op0(x d) (setf (svref d 0)
(the fixnum
(1+ (the fixnum (svref d 0))))))
(defun op1(x d) (SPADCALL x (svref d 1)))
(defun op2(x d) (SPADCALL x (svref d 2)))
(defparameter d1 (GETREFV 3))
(defparameter d2 (GETREFV 2))
(defparameter d3 (GETREFV 3))
(setf (aref d3 1) (cons #'op0 d1))
(setf (aref d3 2) (cons #'op1 d3))
(setf (aref d1 1) (cons #'op2 d3))
(setf (aref d1 2) (cons #'op1 d1))
(setf (aref d2 0) (cons #'op2 d1))
(setf (aref d1 0) 0)
(defun do_it (n)
(declare (type fixnum n))
(dotimes (i n) (SPADCALL 0 (svref d2 0)))
(aref d1 0))
--
Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28009 (Spain)
http://juanjose.garciaripoll.googlepages.com
More information about the ecl-devel
mailing list