[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Compilation of methods per class.



Has anybody developed a method class that "compiles" methods
by building a separate big lambda for each method on each class?
The finalized method lambda for each class would have method selection
and combination already done (with the code for auxiliary methods and
call-next-methods embedded within them).

----
E.g.  Given:

(defmethod foo ((self class1))
  (foo-class1-body))

(defmethod foo :around ((self class2))
  (foo-class2-body-begin)
  (call-next-method)
  (foo-class2-body-end))

(defmethod foo :after ((self class3))
  (foo-class3-body))

(defclass runtime12 (class2 class1) ()())
(defclass runtime13 (class3 class1) ()())

With this, the compiled foo method's lambda for runtime12 would 
end up (roughly) something like:

(defun foo-runtime12-lambda (self)
  (foo-class2-body-begin)
  (funcall #'foo-class1-lambda self)
  (foo-class2-body-end))

And for runtime13:

(defun foo-runtime13-lambda (self)
  (funcall #'foo-class1-lambda self)
  (funcall #'foo-class3-lambda self))

With foo-class1-lambda, etc. being the obvious.

---

Although this would take more code size (since each class used at run
time would have to have its own lambda for each method), it would
seem to dramatically speed up runtime processing, since
there wouldn't have to be any method combination each time a
method is called.  It would especially speed up processing for
systems in which inner-loop methods called have several auxilary methods.
And as long as their aren't too many different classes with actual
instances at runtime, then the extra space needed for the compiled
lambdas shouldn't be too large.  Of course, it would be especially
helpful if we could choose for each method's generic function whether
we want it's methods to be compiled by class or not.

So, before I go and code this up myself, has anybody done this or a
variation of it?  Do any of the vendor's CLOS versions do it?  And
is there a reason that PCL doesn't do it, besides the extra space
it would need (and perhaps complexity of PCL)?

Thanks,

- Trent Lange
lange@cs.ucla.edu