[closer-devel] using a custom unbound slot marker

Attila Lendvai attila.lendvai at gmail.com
Mon Oct 30 15:13:50 UTC 2006


On 10/30/06, Pascal Costanza <pc at p-cos.net> wrote:
>
> OK, I'll see what I can do... ;)
>

cool!

fyi, i've managed to generate accessors with this overhead on sbcl:

;; standard
Evaluation took:
  0.225 seconds of real time
  0.216967 seconds of user run time
  0.0 seconds of system run time
  0 calls to %EVAL
  0 page faults and
  45,008 bytes consed.

;; mine with minimal extra code
Evaluation took:
  0.642 seconds of real time
  0.618906 seconds of user run time
  0.012998 seconds of system run time
  [Run times include 0.099 seconds GC run time.]
  0 calls to %EVAL
  0 page faults and
  32,014,176 bytes consed.

unfortunately i don't know where the consing comes and probably an extra
boundp call should not make it 3 times slower then standard accessors.

as far as i can see my code should not be consing, and when going though the
svuc, even the less optimized verision (also calling
slot-definition-location at runtime) is not consing. so i suspect it must be
the way i'm generating the accessors:

(defmethod finalize-inheritance :after ((class computed-class))
  (loop for direct-slot :in (class-direct-slots class)
        for effective-slot = (find-slot class (slot-definition-name
direct-slot))
        when (typep effective-slot 'computed-effective-slot-definition) do
        (assert (and (<= (length (slot-definition-readers direct-slot)) 1)
                     (<= (length (slot-definition-writers direct-slot)) 1))
                () "Computed class does not support multiple readers and/or
writers.")
        (let ((reader (first (slot-definition-readers direct-slot)))
              (writer (first (slot-definition-writers direct-slot))))
          #+generate-custom-reader
          (when reader
            ;; FIXME: this setf is a KLUDGE to stop sbcl from generating
it's own reader after (?!) this
            (setf (slot-definition-readers direct-slot) nil)
            (let ((reader-gf (ensure-generic-function reader)))
              (ensure-method reader-gf
                             `(lambda (object)
                               (declare #.(optimize-declaration))
                               ,(slot-value-using-class-body
effective-slot))
                             :specializers (list class))))
          #+generate-custom-writer
          (when writer
            ;; FIXME: this setf is a KLUDGE to stop sbcl from generating
it's own writer after (?!) this
            (setf (slot-definition-writers direct-slot) nil)
            (ensure-generic-function writer)
            (let ((writer-gf (ensure-generic-function writer)))
              (ensure-method writer-gf
                             `(lambda (new-value object)
                               (declare #.(optimize-declaration))
                               ,(setf-slot-value-using-class-body
effective-slot))
                             :specializers (list (find-class 't)
class)))))))

it's not really important for now, but maybe someone can spot something.
also the kludge is probably only needed because i'm doing this at the wrong
point in the MOP.

-- 
- attila

"- The truth is that I've been too considerate, and so became
unintentionally cruel...
- I understand.
- No, you don't understand! We don't speak the same language!"
(Ingmar Bergman - Smultronstället)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/closer-devel/attachments/20061030/c454f12d/attachment.html>


More information about the closer-devel mailing list